-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathyou-are-cancelled.d.ts
121 lines (105 loc) · 3.37 KB
/
you-are-cancelled.d.ts
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* An error that indicates that a cancellation has occurred.
*/
export class OperationCancellationError extends Error
{
/**
* Creates a new error that indicates that a cancellation has occurred.
*
* @param message An optional explanation as to why the cancellation has occurred.
*/
constructor(message? : string);
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
* A function that will be executed when a cancellation has been requested.
*/
export interface OperationCancellationCallback
{
(error : OperationCancellationError) : void;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
* Responsible for propagating the cancellation requested by its associative source.
*/
export class CancellationToken implements PromiseLike<void>
{
/**
* Indicates whether the token is capable of being in a cancelled state.
*/
readonly isCancelable : boolean;
/**
* Indicates whether a cancellation has been requested by its associative source.
*/
readonly isCancellationRequested : boolean;
/**
* Reflects the reason for why the cancellation was requested.
*
* If a cancellation has not been requested or a reason was not provided at cancellation then this will be `null`.
*/
readonly reason : string | null;
/**
* Registers a callback function to execute when a cancellation has been requested.
*
* @param callback A function that you want to be executed when a cancellation has been requested.
*
* @returns The provided callback function.
*/
register(callback : OperationCancellationCallback) : OperationCancellationCallback;
/**
* Deregisters a previously registered callback that would execute when a cancellation has been requested.
*
* @param callback The function that you no longer want to be executed when a cancellation has been requested.
*/
deregister(callback : OperationCancellationCallback) : void;
/**
* Throws an `OperationCancellationError` if a cancellation has already been requested.
*
* This is the same as:
*
* ``` js
* if (token.isCancellationRequested)
* {
* throw new OperationCancellationError();
* }
* ```
*/
throwIfCancellationRequested() : void;
/**
* Converts this token into an `AbortSignal` object.
*
* @returns An `AbortSignal` object that reflects the cancellation state of this token.
*/
toAbortSignal() : AbortSignal;
/**
* @inheritdoc
*/
then(onFulfilled ?: ((value : void) => any | PromiseLike<any>) | null | undefined, onRejected ?: ((reason : OperationCancellationError) => any | PromiseLike<any>) | null | undefined) : PromiseLike<any>;
/**
* A dummy token that is not capable of being in a cancelled state.
*/
static readonly None : CancellationToken;
}
// - - - - - - - - - - - - - - - - - - - - - - - - - - - -
/**
* Responsible for signalling that an operation wants to be cancelled.
*/
export class CancellationTokenSource
{
/**
* Indicates whether a cancellation has been requested.
*/
readonly isCancellationRequested : boolean;
/**
* A unique token that is responsible for propagating the cancellation requested by this source.
*
* This is what you pass around to asynchronous operations that can be cancelled.
*/
readonly token : CancellationToken;
/**
* Signals a request for cancellation.
*
* @param reason An optional explanation as to why the cancellation is being requested.
*/
cancel(reason? : string) : void;
}