commit | author | age
|
bad748
|
1 |
/* |
W |
2 |
* Copyright (c) 2014, Facebook, Inc. |
|
3 |
* All rights reserved. |
|
4 |
* |
|
5 |
* This source code is licensed under the BSD-style license found in the |
|
6 |
* LICENSE file in the root directory of this source tree. An additional grant |
|
7 |
* of patent rights can be found in the PATENTS file in the same directory. |
|
8 |
* |
|
9 |
*/ |
|
10 |
|
|
11 |
#import <Foundation/Foundation.h> |
|
12 |
|
|
13 |
NS_ASSUME_NONNULL_BEGIN |
|
14 |
|
13e53a
|
15 |
@class BFTask<__covariant ResultType>; |
bad748
|
16 |
|
W |
17 |
/*! |
|
18 |
A BFTaskCompletionSource represents the producer side of tasks. |
|
19 |
It is a task that also has methods for changing the state of the |
|
20 |
task by settings its completion values. |
|
21 |
*/ |
|
22 |
@interface BFTaskCompletionSource<__covariant ResultType> : NSObject |
|
23 |
|
|
24 |
/*! |
|
25 |
Creates a new unfinished task. |
|
26 |
*/ |
|
27 |
+ (instancetype)taskCompletionSource; |
|
28 |
|
|
29 |
/*! |
|
30 |
The task associated with this TaskCompletionSource. |
|
31 |
*/ |
|
32 |
@property (nonatomic, strong, readonly) BFTask<ResultType> *task; |
|
33 |
|
|
34 |
/*! |
|
35 |
Completes the task by setting the result. |
|
36 |
Attempting to set this for a completed task will raise an exception. |
|
37 |
@param result The result of the task. |
|
38 |
*/ |
13e53a
|
39 |
- (void)setResult:(nullable ResultType)result NS_SWIFT_NAME(set(result:)); |
bad748
|
40 |
|
W |
41 |
/*! |
|
42 |
Completes the task by setting the error. |
|
43 |
Attempting to set this for a completed task will raise an exception. |
|
44 |
@param error The error for the task. |
|
45 |
*/ |
13e53a
|
46 |
- (void)setError:(NSError *)error NS_SWIFT_NAME(set(error:)); |
bad748
|
47 |
|
W |
48 |
/*! |
|
49 |
Completes the task by marking it as cancelled. |
|
50 |
Attempting to set this for a completed task will raise an exception. |
|
51 |
*/ |
|
52 |
- (void)cancel; |
|
53 |
|
|
54 |
/*! |
|
55 |
Sets the result of the task if it wasn't already completed. |
|
56 |
@returns whether the new value was set. |
|
57 |
*/ |
13e53a
|
58 |
- (BOOL)trySetResult:(nullable ResultType)result NS_SWIFT_NAME(trySet(result:)); |
bad748
|
59 |
|
W |
60 |
/*! |
|
61 |
Sets the error of the task if it wasn't already completed. |
|
62 |
@param error The error for the task. |
|
63 |
@returns whether the new value was set. |
|
64 |
*/ |
13e53a
|
65 |
- (BOOL)trySetError:(NSError *)error NS_SWIFT_NAME(trySet(error:)); |
bad748
|
66 |
|
W |
67 |
/*! |
|
68 |
Sets the cancellation state of the task if it wasn't already completed. |
|
69 |
@returns whether the new value was set. |
|
70 |
*/ |
|
71 |
- (BOOL)trySetCancelled; |
|
72 |
|
|
73 |
@end |
|
74 |
|
|
75 |
NS_ASSUME_NONNULL_END |