Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8777287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:14:41+00:00 2026-06-13T19:14:41+00:00

Many, if not most, web services have a rate limit for clients. Delicious says

  • 0

Many, if not most, web services have a rate limit for clients. Delicious says a client can make one request per second; Twitter has limits per end-point; I’m sure Facebook and Flickr and Foursquare have their own idea.

You can easily limit an iOS application to a single request at a time using an NSOperationQueue.

But how do you limit an application to making, say, only one request per second?

I’ve looked at the sample code by Apple, AFNetworking, ASINetwork and a few others, and none seem to solve this problem. This seems odd to me. I’ll concede that I could be missing something very obvious…

Some parameters:

  • Assume I have an NSOperationQueue for network operations and the request is an NSOperation (could also be a GCD queue I suppose, but this is what I’ve mostly been working with)
  • The same rate limit is used for each request in the queue
  • I’m looking for a solution in iOS, but general ideas might be useful

Possible solutions:

  • sleep statement in the NSOperation (it’s a queue/thread so this wouldn’t block anything else)
  • NSTimer in the NSOperation
  • performSelector: in the NSOperation (I patched ASINetworking to use this approach, though I’m not using it and didn’t push the change upstream)
  • Start/stop the queue (using KVO?) to make sure the rate limit is not exceeded
  • Special “sleep” NSOperation. This would be a task that the next network operation would be dependent upon
  • Completely ignore the rate limit and just pause a bit when you get the “exceeded rate limit” error response

These all seem quite messy. Operations that sleep would likely prevent forms of “priority” queue. Starting/stopping the queue seems fragile. Ignoring the limit is rude.

To be clear, I have solved this problem. But the solution seems “messy” and somewhat fragile. I’d like to know if there’s a better, cleaner option.

Ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:14:42+00:00Added an answer on June 13, 2026 at 7:14 pm
    @implementation SomeNSOperationSubClass {
        BOOL complete;
        BOOL stopRunLoop;
        NSThread *myThread;
    }
    
    -(void) rateLimitMonitor:(NSTimer *)theTimer {
        [theTimer invalidate];
    }
    
    -(void) main {
        myThread = [NSThread currentThread];
    
        NSTimer *myTimer = [NSTimer timerWithTimeInterval:1 target:self  selector:@selector(rateLimitMonitor:) userInfo:nil repeats:NO];
        [[NSRunLoop currentRunLoop] addTimer:myTimer forMode:NSDefaultRunLoopMode];
    
        [self doAsyncThing];
    
        while ((!stopRunLoop || [myTimer isValid]) && [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
        complete = YES;
    }
    
    -(void) internalComplete {
        stopRunLoop = YES;
    }
    
    -(void) setComplete {
        [self performSelector:@selector(internalComplete) onThread:myThread withObject:nil waitUntilDone:NO];
    }
    
    -(BOOL) isFinished {
        return complete;
    }
    
    @end
    

    and in your async callback

        [myNSOperationSubClass setComplete];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have not used many lambda expressions before and I ran into a case
I can not directly user $('commentbody') because there are many comments and selection needs
I wonder how many users still have not upgraded their phones from version 2.2.1.
I'm using SQL Server 2005 with Reporting Services. I have many reports installed, some
I have to write a web application, and I am not sure which technology
I am looking for a way to expose many (2000+) similar web services through
I have two related questions about Web services: (1) I'm currently writing a set
I have a web page with many select boxes, which should each contain the
There are lots of questions on how to strip html tags, but not many
As I do not trust many benchmarks out there, because they are not actually

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.