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 "FBLPromiseError.h"
|
|
|
18 |
|
|
|
19 |
NS_ASSUME_NONNULL_BEGIN
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
Promises synchronization construct in Objective-C.
|
|
|
23 |
*/
|
|
|
24 |
@interface FBLPromise<__covariant Value> : NSObject
|
|
|
25 |
|
|
|
26 |
/**
|
|
|
27 |
Default dispatch queue used for `FBLPromise`, which is `main` if a queue is not specified.
|
|
|
28 |
*/
|
|
|
29 |
@property(class) dispatch_queue_t defaultDispatchQueue NS_REFINED_FOR_SWIFT;
|
|
|
30 |
|
|
|
31 |
/**
|
|
|
32 |
Creates a pending promise.
|
|
|
33 |
*/
|
|
|
34 |
+ (instancetype)pendingPromise NS_REFINED_FOR_SWIFT;
|
|
|
35 |
|
|
|
36 |
/**
|
|
|
37 |
Creates a resolved promise.
|
|
|
38 |
|
|
|
39 |
@param resolution An object to resolve the promise with: either a value or an error.
|
|
|
40 |
@return A new resolved promise.
|
|
|
41 |
*/
|
|
|
42 |
+ (instancetype)resolvedWith:(nullable id)resolution NS_REFINED_FOR_SWIFT;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
Synchronously fulfills the promise with a value.
|
|
|
46 |
|
|
|
47 |
@param value An arbitrary value to fulfill the promise with, including `nil`.
|
|
|
48 |
*/
|
|
|
49 |
- (void)fulfill:(nullable Value)value NS_REFINED_FOR_SWIFT;
|
|
|
50 |
|
|
|
51 |
/**
|
|
|
52 |
Synchronously rejects the promise with an error.
|
|
|
53 |
|
|
|
54 |
@param error An error to reject the promise with.
|
|
|
55 |
*/
|
|
|
56 |
- (void)reject:(NSError *)error NS_REFINED_FOR_SWIFT;
|
|
|
57 |
|
|
|
58 |
+ (instancetype)new NS_UNAVAILABLE;
|
|
|
59 |
- (instancetype)init NS_UNAVAILABLE;
|
|
|
60 |
@end
|
|
|
61 |
|
|
|
62 |
@interface FBLPromise<Value>()
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
Adds an object to the set of pending objects to keep strongly while the promise is pending.
|
|
|
66 |
Used by the Swift wrappers to keep them alive until the underlying ObjC promise is resolved.
|
|
|
67 |
|
|
|
68 |
@param object An object to add.
|
|
|
69 |
*/
|
|
|
70 |
- (void)addPendingObject:(id)object NS_REFINED_FOR_SWIFT;
|
|
|
71 |
|
|
|
72 |
@end
|
|
|
73 |
|
|
|
74 |
#ifdef FBL_PROMISES_DOT_SYNTAX_IS_DEPRECATED
|
|
|
75 |
#define FBL_PROMISES_DOT_SYNTAX __attribute__((deprecated))
|
|
|
76 |
#else
|
|
|
77 |
#define FBL_PROMISES_DOT_SYNTAX
|
|
|
78 |
#endif
|
|
|
79 |
|
|
|
80 |
@interface FBLPromise<Value>(DotSyntaxAdditions)
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
Convenience dot-syntax wrappers for FBLPromise.
|
|
|
84 |
Usage: FBLPromise.pending()
|
|
|
85 |
FBLPromise.resolved(value)
|
|
|
86 |
|
|
|
87 |
*/
|
|
|
88 |
+ (instancetype (^)(void))pending FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE("");
|
|
|
89 |
+ (instancetype (^)(id __nullable))resolved FBL_PROMISES_DOT_SYNTAX NS_SWIFT_UNAVAILABLE("");
|
|
|
90 |
|
|
|
91 |
@end
|
|
|
92 |
|
|
|
93 |
NS_ASSUME_NONNULL_END
|