0

I have a iOS app where at a given moment I have do 1+ async api calls which needs to be completed before I can send the final async call to my server. What is the best way to do it? e.g.

Start

  1. async call to server 1
  2. async call to server 2
  3. wait for #1 and #2 to get over before async call to server 3

I am using Obj-c

1
  • What have you tried? Did you try to search for a way how to achieve this? Many ways. Show some effort and code which doesn't work for you. Commented Jul 20, 2020 at 19:48

1 Answer 1

0

As zrzka points out there are many ways to do this. Here is one suggestion.

Use an NSOperationQueue and set async call to server 1 and 2 as dependencies on call to server 3. Here is an outline.

NSOperationQueue * queue = ...

// s1, s2 and s3 are blocks that do your work
NSOperation * server1 = [NSBlockOperation blockOperationWithBlock:s1];
NSOperation * server2 = [NSBlockOperation blockOperationWithBlock:s2];
NSOperation * server3 = [NSBlockOperation blockOperationWithBlock:s3];

[server3 addDependency:server1];
[server3 addDependency:server2];

// Now you can schedule
[queue addOperation:server1];
[queue addOperation:server2];
[queue addOperation:server3];

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.