Skip to content

Instantly share code, notes, and snippets.

@MartinJNash
Last active August 29, 2015 14:08
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 MartinJNash/1c8d6719874e15e89b48 to your computer and use it in GitHub Desktop.
Save MartinJNash/1c8d6719874e15e89b48 to your computer and use it in GitHub Desktop.
struct Dispatch {
static func onMainQueue(block:()->()) {
onMainQueueWithDelay(0, block: block)
}
static func onMainQueueWithDelay(delay: NSTimeInterval, block:()->()) {
var queue: dispatch_queue_t = dispatch_get_main_queue()
onQueue(queue, withDelay: delay, block: block)
}
static func onQueue(queue: dispatch_queue_t, withDelay delay: NSTimeInterval, block: ()->()) {
var time: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(delay * Double(NSEC_PER_SEC)))
dispatch_after(time, queue, block)
}
}
Dispatch.onMainQueue() {}
Dispatch.onMainQueueWithDelay(1.0) {}
let q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
Dispatch.onQueue(q, withDelay: 20) {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment