Currently I am using PromiseKit to chain a logic, which is like the following:
[NSURLConnection promise:rq1].then(^(id data1) {
return [NSURLConnection promise:rq2];
}).then(^(id data2) {
return [NSURLConnection promise:rq3];
}).then(^(id data3) {
return [self promiseToDoSomeWorkOnData:data3];
}).finally(^{
[self cleanup];
});
The problem that I am facing is that the method I call in the finally
clause is asynchronous, but I have no way to chain the finally
method together with the other promises so that any usage of the whole piece of code somewhere else waits also for the finally
clause to finish before continuing to a next promise.