1 |
efrain |
1 |
/**
|
|
|
2 |
Copyright 2018 Google Inc. All rights reserved.
|
|
|
3 |
|
|
|
4 |
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
5 |
you may not use this file except in compliance with the License.
|
|
|
6 |
You may obtain a copy of the License at:
|
|
|
7 |
|
|
|
8 |
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
9 |
|
|
|
10 |
Unless required by applicable law or agreed to in writing, software
|
|
|
11 |
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
12 |
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
13 |
See the License for the specific language governing permissions and
|
|
|
14 |
limitations under the License.
|
|
|
15 |
*/
|
|
|
16 |
|
|
|
17 |
#import "FBLPromise+Catch.h"
|
|
|
18 |
|
|
|
19 |
#import "FBLPromisePrivate.h"
|
|
|
20 |
|
|
|
21 |
@implementation FBLPromise (CatchAdditions)
|
|
|
22 |
|
|
|
23 |
- (FBLPromise *)catch:(FBLPromiseCatchWorkBlock)reject {
|
|
|
24 |
return [self onQueue:FBLPromise.defaultDispatchQueue catch:reject];
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
- (FBLPromise *)onQueue:(dispatch_queue_t)queue catch:(FBLPromiseCatchWorkBlock)reject {
|
|
|
28 |
NSParameterAssert(queue);
|
|
|
29 |
NSParameterAssert(reject);
|
|
|
30 |
|
|
|
31 |
return [self chainOnQueue:queue
|
|
|
32 |
chainedFulfill:nil
|
|
|
33 |
chainedReject:^id(NSError *error) {
|
|
|
34 |
reject(error);
|
|
|
35 |
return error;
|
|
|
36 |
}];
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
@end
|
|
|
40 |
|
|
|
41 |
@implementation FBLPromise (DotSyntax_CatchAdditions)
|
|
|
42 |
|
|
|
43 |
- (FBLPromise* (^)(FBLPromiseCatchWorkBlock))catch {
|
|
|
44 |
return ^(FBLPromiseCatchWorkBlock catch) {
|
|
|
45 |
return [self catch:catch];
|
|
|
46 |
};
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
- (FBLPromise* (^)(dispatch_queue_t, FBLPromiseCatchWorkBlock))catchOn {
|
|
|
50 |
return ^(dispatch_queue_t queue, FBLPromiseCatchWorkBlock catch) {
|
|
|
51 |
return [self onQueue:queue catch:catch];
|
|
|
52 |
};
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
@end
|