Skip to content

Instantly share code, notes, and snippets.

@pietrorea
Created September 22, 2016 20:14
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 pietrorea/7bee493e010877aea2b4f6e87454ad8d to your computer and use it in GitHub Desktop.
Save pietrorea/7bee493e010877aea2b4f6e87454ad8d to your computer and use it in GitHub Desktop.
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