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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:28:51+00:00 2026-06-10T10:28:51+00:00

i have a problem with queued functions. i want to run my function and

  • 0

i have a problem with queued functions. i want to run my function and when my first function finishes running, i want to start other one.

-(void)firstFunct
{

// sending and getting information from server.
// doing sth and creating data to use in my second function.

} 

and my second function is:

-(void)secondFunct
{
// using data coming from first function

}

i am now using these 2 functions in like that

-(void)ThirdFunct
{

   [self firstFunct];

   [self performSelector:@selector(secondFunct) withObject:nil afterDelay:0.5];


}

but there is a problem that this method is not good to use. i want to learn if there is an efficient way to run the functions one after the other.

  • 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-10T10:28:52+00:00Added an answer on June 10, 2026 at 10:28 am

    Cocoa offers nice concurrency management classes like NSOperation and NSOperationQueue. You could use them to simplify the logic behind chaining your asynchronous calls without creating explicit connections in code to call method 3 after work 2 completes, and method 2 after work 1 completes, and so on. Using dependency management, you could easily specify those dependencies between your operations.

    Here’s a simple example of how you would use that code. Suppose you are downloading some data asynchronously in all those three methods, and you’ve created a NSOperation subclass called DownloadOperation.

    First, create a NSOperationQueue.

    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    

    Then, create the three download operations.

    DownloadOperation *a = [[DownloadOperation alloc] init];
    DownloadOperation *b = [[DownloadOperation alloc] init];
    DownloadOperation *c = [[DownloadOperation alloc] init];
    

    Then, specify the dependencies between your operations. Dependencies simply say that an operation can run only if all the operations it depends upon are complete. In your example, the dependencies look like c <- b <- a, which can be broken down into two steps:

    [b addDependency:a];
    [c addDependency:b];
    

    Now add these operations to the queue.

    [queue addOperations:@[ a, b, c ] waitUntilFinished:NO];
    

    The queue will automatically start processing all operations at this point, but since we’ve creating this chaining sort of a dependency, they will be executed one after the other in our particular example.

    I’ve created a sample project on github demonstrating it with a simple example at https://github.com/AnuragMishra/ChainedOperationQueue. It fakes an asynchronous operation by creating a timer, and when the timer finishes, the operation is marked complete. It’s written using Xcode 4.5, so let me know if you have issues compiling it in older versions.

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

Sidebar

Related Questions

I have problem with repopulating form_upload after validation. Other input fields or selectboxes are
I have problem with show or hide form in Window Form Application. I start
I have a problem with Gearman and the worker for PHP. I want to
i have a problem with running my jQuery scripts in Internet Explorer at my
I'm very new to Scala and I have run in to a problem. I
I have strange problem with the delay function here using the HTML function with
I have a embarrassingly parallel problem that I want to execute on multiple processors.
I have problem with python multithreaded Queues. I have this script, where producer take
I have problem with http://abfoodpolicy.com/ . In IE 8 and 9 the right sidebar
I have problem with my query on C, I’m using the oci8 driver. This

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.