Re: rate limiting calls
Re: rate limiting calls
- Subject: Re: rate limiting calls
- From: Seth Willits <email@hidden>
- Date: Tue, 28 May 2013 10:35:30 -0700
A while ago I was fiddling with various APIs to do rate limited calls. This is the simplest one. Morph it as you please. Maybe it'll be useful to someone.
@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
--
Seth Willits
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden