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 7023653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:44:17+00:00 2026-05-27T23:44:17+00:00

I’m trying to queue up some TWRequest calls using NSInvocationOperation. It seems to add

  • 0

I’m trying to queue up some TWRequest calls using NSInvocationOperation. It seems to add the method calls in the correct order, but the doSomething: methods get called at the same time pretty much, ie run concurrently, rather than one after the other, which is what I want to achieve.

In addition, the complete in the wrong order, which suggests it’s not running one after the other…

- (void)prepare {

    if(!self.queue){
        self.queue = [[NSOperationQueue alloc] init];
        [self.queue setMaxConcurrentOperationCount:1];
    }

    for(NSString *text in calls){

        NSLog(@"Adding to Queue... %@", text);
        NSInvocationOperation *indexOperation = [[NSInvocationOperation alloc] initWithTarget:self  
                                                                                     selector:@selector(doSomething:) object:text];
        [self.queue addOperation:indexOperation];
    }     
}

- (void)doSomething:(NSString*)someText {

    TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://something.com"] parameters:nil requestMethod:TWRequestMethodGET];
    NSLog(@"About to Perform Request... %@", someText);
    [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
     {
         dispatch_sync(dispatch_get_main_queue(), ^{
              // works fine
              NSLog(@"Network Finished... %@", someText);
         });
     }];
}

In the log I see this:

2011-12-30 18:34:34.553 app[32745:10703] Adding to Queue... 1
2011-12-30 18:34:34.555 app[32745:10703] Adding to Queue... 2
2011-12-30 18:34:34.556 app[32745:10703] Adding to Queue... 3
2011-12-30 18:34:34.557 app[32745:13e03] About to Perform Request... 1
2011-12-30 18:34:34.560 app[32745:13e03] About to Perform Request... 2
2011-12-30 18:34:34.563 app[32745:13e03] About to Perform Request... 3
2011-12-30 18:34:35.303 app[32745:10703] Network finished... 3
2011-12-30 18:34:35.454 app[32745:10703] Network finished... 2
2011-12-30 18:34:35.601 app[32745:10703] Network finished... 1

I’m expecting to see (2) to Perform Request after (1) has finished etc… Any pointers?

  • 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-05-27T23:44:18+00:00Added an answer on May 27, 2026 at 11:44 pm

    The operation queue is working fine. As @Joe said in the comment, performRequestWithHandler: starts an asynchronous connection and returns immediately. You can see this by adding an NSLog to the end of doSomething as follows:

    - (void)doSomething:(NSString*)someText {
        TWRequest *request = [[TWRequest alloc] initWithURL:[NSURL URLWithString:@"http://something.com"] parameters:nil requestMethod:TWRequestMethodGET];
        NSLog(@"About to Perform Request... %@", someText);
        [request performRequestWithHandler:^(NSData *responseData, NSHTTPURLResponse *urlResponse, NSError *error)
         {
             dispatch_sync(dispatch_get_main_queue(), ^{
                  // works fine
                  NSLog(@"Network Finished... %@", someText);
             });
         }];
        NSLog(@"doSomething Finished");
    }
    

    To have each request happen serially you need to either make the request synchronous within the operation (use the signedRequest method and a synchronous NSURLConnection) or don’t use an operation queue and invoke the next request in the completion handler of the current request. Keep in mind that if you use an operation queue the order in which operations are performed is not based on the order they are added. You might consider using GCD directly with a serial dispatch queue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into

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.