Created
January 30, 2015 20:27
-
-
Save Air-Craft/c1a77ec3c314090175d9 to your computer and use it in GitHub Desktop.
One-off timer with GCD on high priority thread #concurrency #GCD #objective-c #advanced
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
| dispatch_source_t _timer; | |
| _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0)); | |
| dispatch_source_set_timer(_timer, | |
| dispatch_walltime(NULL, <#timeout#> * NSEC_PER_SEC), | |
| 1 * NSEC_PER_SEC, // this doenst really matter | |
| <# 0.01 (tolerance) #> * NSEC_PER_SEC); | |
| dispatch_source_set_event_handler(_timer, ^{ | |
| dispatch_source_cancel(_timer); // cancel the repeat | |
| // YOUR STUFF | |
| }); | |
| dispatch_resume(_timer); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment