forked from mxcl/PromiseKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPMKPromise+Pause.m
30 lines (24 loc) · 946 Bytes
/
PMKPromise+Pause.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
#import "PromiseKit/Promise+Pause.h"
#define Queue dispatch_get_main_queue()
@implementation PMKPromise (Pause)
- (PMKPromise *(^)(NSTimeInterval))pause {
return ^(NSTimeInterval delay) {
return self.then(^(id value){
return [self.class new:^(PMKPromiseFulfiller fulfiller, PMKPromiseRejecter rejecter) {
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC));
dispatch_after(time, Queue, ^{
fulfiller(PMKManifold(value ?: @(delay), @(delay)));
});
}];
});
};
}
+ (PMKPromise *)pause:(NSTimeInterval)delay {
return [self new:^(PMKPromiseFulfiller fulfiller, PMKPromiseRejecter rejecter) {
dispatch_time_t time = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delay * NSEC_PER_SEC));
dispatch_after(time, Queue, ^{
fulfiller(@(delay));
});
}];
}
@end