//
//  AsyncUtil.swift
//  Pods
//
//  Created by Thierry on 16/6/14.
//
//

import Foundation

/**
 Postpone execute [task].
 
 - parameter delay:   time to delay
 - parameter closure: the code to postpone execute.
 */
public func delay(_ delay: Double, closure:@escaping ()->()) {
    DispatchQueue.main.asyncAfter(
        deadline: DispatchTime.now() + Double(Int64(delay * Double(NSEC_PER_SEC))) / Double(NSEC_PER_SEC), execute: closure)
}

/**
 Execute [task] asynchronously.
 
 - parameter task: the code to execute asynchronously.
 */
public func doAsync(_ task: @escaping ()->()) {
    DispatchQueue.global().async(execute: task)
}

/**
 Execute [task] on the application UI thread.
 
 - parameter task: task the code to execute UI thread.
 */
public func uiThread(_ task: @escaping ()->()) {
    DispatchQueue.main.async(execute: task)
}
