Created
March 19, 2013 22:59
-
-
Save swillits/5200935 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
dispatch_source_t dispatch_coalesce_source_create(dispatch_queue_t queue) | |
{ | |
dispatch_source_t src = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue); | |
dispatch_resume(src); | |
return src; | |
} | |
void dispatch_coalesce(dispatch_source_t src, double time, void (^block)(void)) | |
{ | |
dispatch_source_set_timer(src, dispatch_time(DISPATCH_TIME_NOW, time * NSEC_PER_SEC), DISPATCH_TIME_FOREVER, 0); | |
dispatch_source_set_event_handler(src, ^{ | |
block(); | |
}); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment