Last active
August 29, 2015 14:08
-
-
Save MartinJNash/1c8d6719874e15e89b48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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