• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: rate limiting calls
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

References: 
 >rate limiting calls (From: Torsten Curdt <email@hidden>)
 >Re: rate limiting calls (From: Igor Elland <email@hidden>)
 >Re: rate limiting calls (From: Torsten Curdt <email@hidden>)
 >Re: rate limiting calls (From: John Pannell <email@hidden>)
 >Re: rate limiting calls (From: Torsten Curdt <email@hidden>)
 >Re: rate limiting calls (From: Torsten Curdt <email@hidden>)
 >Re: rate limiting calls (From: Torsten Curdt <email@hidden>)
 >Re: rate limiting calls (From: Dave Fernandes <email@hidden>)
 >Re: rate limiting calls (From: Kyle Sluder <email@hidden>)

  • Prev by Date: Re: Building an MVC based App for Mac OS X - NOT for iOS
  • Next by Date: Re: rate limiting calls
  • Previous by thread: Re: rate limiting calls
  • Next by thread: Re: rate limiting calls
  • Index(es):
    • Date
    • Thread