I have several asynchronous calls which I would combine in one call:
-(void) loadA:(ArrayBlock)completion failure(FailureBlock):failure;
-(void) loadB:(ArrayBlock)completion failure(FailureBlock):failure;
-(void) loadC:(ArrayBlock)completion failure(FailureBlock):failure;
The combined method, which uses the calls above:
- (void) loadAll:(ObjectBlock)completion;
The completion block contains an object with three arrays called array[A-C]
. If any of the child calls fail the respective array in the object is simply set to nil.
Instead of nesting those three blocks and calling the next one on failure or completion of the preceding (This gets really messy) - I want to do something like the following using GCD:
- Add all calls to queue
- Wait until all calls have finished (either success or failure block was called)
- Combine all the results from the completion blocks and call the completion block of the
loadAll
method.
I know this is possible in GCD with synchronous calls but I don't see how to achieve this with my three asynchronous "child calls".