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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:05:57+00:00 2026-06-08T18:05:57+00:00

I am working on an iOS app that has a highly asynchronous design. There

  • 0

I am working on an iOS app that has a highly asynchronous design. There are circumstances where a single, conceptual “operation” may queue many child blocks that will be both executed asynchronously and receive their responses (calls to remote server) asynchronously. Any one of these child blocks could finish execution in an error state. Should an error occur in any child block, any other child blocks should be cancelled, the error state should be percolated up to the parent, and the parent’s error-handling block should be executed.

I am wondering what design patterns and other tips that might be recommended for working within an environment like this?

I am aware of GCD’s dispatch_group_async and dispatch_group_wait capabilities. It may be a flaw in this app’s design, but I have not had good luck with dispatch_group_async because the group does not seem to be “sticky” to child blocks.

Thanks in advance!

  • 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-08T18:05:58+00:00Added an answer on June 8, 2026 at 6:05 pm

    There is a WWDC video (2012) that will probably help you out. It uses a custom NSOperationQueue and places the asynchronous blocks inside NSOperationsso you can keep a handle on the blocks and cancel remaining queued blocks.

    An idea would be to have the error handling of the child blocks to call a method on the main thread in the class that handles the NSOperationQueue. The class could then cancel the rest appropriately. This way the child block only need to know about their own thread and the main thread. Here is a link to the video

    https://developer.apple.com/videos/wwdc/2012/

    The video is called “Building Concurrent User Interfaces on iOS”. The relevant part is mainly in the second half, but you’ll probably want to watch the whole thing as it puts it in context nicely.

    EDIT:

    If possible, I’d recommend handling the response in an embedded block, which wraps it nicely together, which is what I think you’re after..

    //Define an NSBlockOperation, and get weak reference to it
    NSBlockOperation *blockOp = [[NSBlockOperation alloc]init];
    __weak NSBlockOperation *weakBlockOp = blockOp;
    
    //Define the block and add to the NSOperationQueue, when the view controller is popped
    //we can call -[NSOperationQueue cancelAllOperations] which will cancel all pending threaded ops
    [blockOp addExecutionBlock: ^{
    
        //Once a block is executing, will need to put manual checks to see if cancel flag has been set otherwise
        //the operation will not be cancelled. The check is rather pointless in this example, but if the
        //block contained multiple lines of long running code it would make sense to do this at safe points
        if (![weakBlockOp isCancelled]) {
    
            //substitute code in here, possibly use *synchronous* NSURLConnection to get
            //what you need. This code will block the thread until the server response
            //completes. Hence not executing the following block and keeping it on the 
            //queue.  
            __block NSData *temp;
            response = [NSData dataWithContentsOfURL:[NSURL URLWithString:urlString]];
    
            [operationQueue addOperationWithBlock:^{
                if (error) {
                      dispatch_async(dispatch_get_main_queue(), ^{
                            //Call selector on main thread to handle canceling
                            //Main thread can then use handle on NSOperationQueue
                            //to cancel the rest of the blocks 
                      });
                else {
                     //Continue executing relevant code....      
                }
            }];
        }
    }];
    [operationQueue addOperation:blockOp];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on an iOS Cocoa app that has a fallback - if the
I'm working with an iOS app that has an animation of a spinning body.
I'm new to iOS development and am working on this app that has a
I'm working on an iOS app that uses a NSMutableURLRequest and a NSURLConnection to
I have been working on a Core Data iOS app that works perfectly through
I am working on an iOS 5 app. I have a view controller that
I have an app prototype that was working on Iphone4 + iOS 4.3, build
I working on a universal iOS app that gets news from an RSS feed.
I'm working on a universal app that uses the camera on iOS devices and
After installing Xcode 3.2.5 iOS 4.2 an app that was perfectly working stopped working.

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.