Skip to content

Instantly share code, notes, and snippets.

@swillits
Created March 18, 2013 01:02
Show Gist options
  • Save swillits/5184358 to your computer and use it in GitHub Desktop.
Save swillits/5184358 to your computer and use it in GitHub Desktop.
@interface GCDCoalescent : NSObject
- (void)dispatchOn:(dispatch_queue_t)queue after:(double)seconds block:(dispatch_block_t)block;
@end
@implementation GCDCoalescent
{
uint64_t count;
}
- (void)dispatchOn:(dispatch_queue_t)queue after:(double)seconds block:(dispatch_block_t)block;
{
uint64_t eventNumber = __sync_add_and_fetch(&count, 1);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC), queue, ^{
if (count > eventNumber) return;
block();
});
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment