This is a design pattern question.
Imagine a programming task where one is developing a client that will interact with a server asynchronously (via streams). Let's say the challenge is to execute an indeterminate number of tasks, each of which may spawn an indeterminate number of child tasks (i.e. - crawling a tree). Each task makes an asynchronous request to the server and provides two blocks (one for handling expected return conditions and one for error conditions) to handle response processing.
In a scenario like this, it's easy for me to see how one might queue the outbound requests, but having that queue emptied does not imply that the holistic task is completed as subsequent response processing could queue more outbound requests. The outbound request queue could hit zero multiple times in the course of completing the holistic task.
Under iOS, what kind of options (design patterns and useful classes) might you suggest for determining when the holistic task was truly completed?
Another wrinkle in this is that in error scenarios (for any child task) I am going to want the holistic task (and all child tasks) to be cancelled.
Thanks in advance!