Skip to content

Instantly share code, notes, and snippets.

@nathanhillyer
Created January 8, 2016 18:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nathanhillyer/648d24b510992d63d164 to your computer and use it in GitHub Desktop.
Save nathanhillyer/648d24b510992d63d164 to your computer and use it in GitHub Desktop.
import Foundation
/**
Executes the closure on the main queue after a set amount of seconds.
- parameter delay: Delay in seconds
- parameter closure: Code to execute after delay
*/
func delayOnMainQueue(delay: Double, closure: ()->()) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_main_queue(), closure)
}
/**
Executes the closure on a background queue after a set amount of seconds.
- parameter delay: Delay in seconds
- parameter closure: Code to execute after delay
*/
func delayOnBackgroundQueue(delay: Double, closure: ()->()) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC))), dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), closure)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment