Skip to content

Instantly share code, notes, and snippets.

@swillits
Created March 19, 2013 22:59
Show Gist options
  • Save swillits/5200935 to your computer and use it in GitHub Desktop.
Save swillits/5200935 to your computer and use it in GitHub Desktop.
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