forked from mxcl/PromiseKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPMKPromise+Until.m
31 lines (25 loc) · 899 Bytes
/
PMKPromise+Until.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#import "PromiseKit/Promise.h"
#import "PromiseKit/Promise+When.h"
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-retain-cycles"
@implementation PMKPromise (Until)
+ (PMKPromise *)until:(id (^)(void))blockReturningPromises catch:(id)failHandler
{
return [PMKPromise new:^(PMKPromiseFulfiller fulfill, PMKPromiseRejecter reject){
__block void (^block)() = ^{
PMKPromise *next = [self when:blockReturningPromises()];
next.then(^(id o){
fulfill(o);
block = nil; // break retain cycle
});
next.catch(^(NSError *error){
[PMKPromise promiseWithValue:error].catch(failHandler).then(block).catch(^{
reject(error);
block = nil; // break retain cycle
});
});
};
block();
}];
}
@end