Created
March 18, 2013 01:02
-
-
Save swillits/5184358 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
@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