1

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.

o15a3d4l11s2
  • 3,969
  • 3
  • 29
  • 40
  • Is there some reason why you don't just change `cleanup` to return a promise, just like you did with `promiseToDoSomeWorkOnData`? Most asynchronous methods offer some completion handler logic, which you can marry with `promiseWithResolverBlock`. – Rob Oct 25 '15 at 15:11
  • 2
    The reason behind using `finally` is that I want the code executed even if some of the `then` clauses fails. – o15a3d4l11s2 Oct 25 '15 at 15:15
  • Yeah, it seems like there should be some rendition of finally that lets you return a promise (though, admittedly, it's going to make the promises and then/finally clauses a little more difficult to follow). – Rob Oct 25 '15 at 16:37

0 Answers0