Created
September 22, 2016 20:14
-
-
Save pietrorea/7bee493e010877aea2b4f6e87454ad8d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
func poll() { | |
let backgroundQueue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0) | |
let source = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, backgroundQueue) | |
let interval: UInt64 = UInt64(10) * NSEC_PER_SEC | |
let leeway: UInt64 = UInt64(0.1) * NSEC_PER_SEC | |
dispatch_source_set_timer(source, DISPATCH_TIME_NOW, interval, leeway) | |
dispatch_source_set_event_handler(source) { () -> Void in | |
self.pollDidFinish(source: source) | |
} | |
dispatch_resume(source) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment