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

  • SEARCH
  • Home
  • 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 7833371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T12:40:38+00:00 2026-06-02T12:40:38+00:00

This probably has something to do with my understanding of blocks and probably how/when

  • 0

This probably has something to do with my understanding of blocks and probably how/when the NSOperationQueue fires it’s operations but I’ll ask anyway:

I have a basic fetch request method:

- (void)fetchActiveUser:(NSString*)username withPassword:(NSString *)password {

    [self setAuthorizationHeaderWithUsername:username password:password];

    // SETS FLAG that we are performing a request
    fetchModeActive = TRUE;

    [self getPath:kTLActiveUserURI parameters:nil success:^(AFHTTPRequestOperation 
      *operation, id responseObject) {

    if ([responseObject isKindOfClass:[NSXMLParser class]]) {
        TLPersonParser *personParser = [[TLPersonParser alloc] 
          initWithParser:responseObject];

        [personParser setDelegate: self];
        [personParser parsePeople];

        [personParser release];

    }
    // handle stuff here.
    NSLog(@"Success!");
    fetchModeActive = FALSE;
    [[NSNotificationCenter defaultCenter] 
      postNotificationName:kTLFetchedActiveUserNotification object:nil];


    } 
    failure:^(__unused AFHTTPRequestOperation *operation, NSError *error) {
      NSLog(@"Failure.");
      fetchModeActive = FALSE;
      [[NSNotificationCenter defaultCenter] 
        postNotificationName:kTLFetchedActiveUserNotification object:error];
    }];


    while(self.fetchModeActive) {
        // WHY DOES THIS RUN INFINITELY?
        // Both above Success: & Failure: blocks set fetchModeActive = FALSE 
        // when complete
        NSLog(@"fetching....");
    }

}

Scroll to the very bottom and you will see my waiting while loop. Why is this running infinitely outputting “fetching…” ?? Both success: and failure: blocks set our fetchModeActive flag back to false ?

My understanding was that this fetch operation runs asynchronously in the background but it looks like the fetch isn’t even being performed!

Any suggestions? Do I need to fire the fetch request in a separate thread?

Thanks!

  • 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-02T12:40:39+00:00Added an answer on June 2, 2026 at 12:40 pm

    To answer your question, the reason why this doesn’t terminate is that you need a __block directive before fetchModeActive in order for the block to be able to change the variable outside the scope of the block. (You’ll also want to use YES and NO as boolean literals, as they’re the convention in Objective-C)

    But to address a larger point, you shouldn’t do it this way. Instead, create an operation, and either -start it–or better yet–add it to an NSOperationQueue. Everything will execute asynchronously in the background and trigger the callbacks when they finish.

    Asynchronous programming can be difficult to get your head around. If you need to define behavior that depends on this method finishing, you may want to add a block parameter to the method, and execute that in the success and failure callbacks.

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

Sidebar

Related Questions

I realize this question has probably been asked numerous times, but I have not
This has probably been answered before, but I have spent some time looking and
All, This question probably has a very simple answer - something I'm overlooking. But
I know this probably has been asked before but I am having issues with
This has probably been answer already but I am trying to return the primary
I know this has been asked probably a thousand times, but I've been biting
This is something that has always bothered me about PHP and I have never
Probably has something to do with CoreAnimation. Does anybody have any example to do
This probably has probably been asked before, but I couldn't find anything relevant. Would
all. This question probably has a devilishly simple answer but it has kept me

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.