Is there a recommended way of implementing a series of activities such that the app remains responsive but the activities aren't all chained together in a nested manner and without using a thread.
Let me try and explain - suppose I have a model class which uses a downloader class to download a zip file, then when its downloaded the model unzips the file, then does something with the unzipped files.
Now if the downloader class informs the model class the download is ready via a delegate like this:
In the downloader class :
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
// ...
[self.delegate zipFileDownloadingCompleted];
}
In the model class :
- (void) zipFileDownloadingCompleted {
[self unzipFile];
[self doSomethingElseWithFile];
[self doSomeOtherStuff];
}
But if unZipFile and doSomethingElseWithFile and doSomeOtherStuff could be lengthy activities which use an asynchronous API then maybe the model class will split these up and only call doSomethingElseWithFile once a delegate on unzipFile has been called, and only call doSomeOtherStuff once a delegate has been called on doSomethingElseWithFile and so on. But is this a valid approach, seems to me everything is chained together and its still synchronous.
How could unZipFile and doSomethingElseWithFile and doSomeOtherStuff be broken up into separate chunks of activity? Is it possible for the app to make itself jump out of the run loop at the end of one activity and then jump back in to do the next activity?
If you're familiar with Brew then what I mean by this is perform one activity during one run through a HandleEvent() invocation, then self-schudule an event so that HandleEvent() will get called again to process the next activity and so on - so the app remains responsive at all time.
I would like to avoid threads if possible, I think event based coding is less complex and less error prone than threads.
I don't know if I explained that very well, hopefully you get the gist.