-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.d.ts
225 lines (182 loc) · 5.9 KB
/
index.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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
declare module 'ember-concurrency' {
import Task from 'ember-concurrency/task';
export function task(generator: Function): PropertyDecorator;
}
declare module 'ember-concurrency/task' {
import TaskInstance from 'ember-concurrency/task-instance';
export enum TaskState {
RUNNING = 'running',
QUEUED = 'queued',
IDLE = 'idle'
}
/**
* The `Task` object lives on a host Ember object (e.g.
* a Component, Route, or Controller). You call the
* `.perform()` method on this object
* to create run individual `TaskInstance`s,
* and at any point, you can call the `.cancelAll()`
* method on this object to cancel all running or enqueued
* `TaskInstance`s.
*/
export default class Task {
/**
* `true` if any current task instances are running.
*/
readonly isRunning: boolean;
/**
* `true` if any future task instances are queued.
*/
readonly isQueued: boolean;
/**
* `true` if the task is not in the running or queued state.
*/
readonly isIdle: boolean;
/**
* The current state of the task: `"running"`, `"queued"` or `"idle"`.
*/
readonly state: TaskState;
/**
* The most recently started task instance.
*/
readonly last: TaskInstance;
/**
* The most recent task instance that is currently running.
*/
readonly lastRunning: TaskInstance;
/**
* The most recently performed task instance.
*/
readonly lastPerformed: TaskInstance;
/**
* The most recent task instance that succeeded.
*/
readonly lastSuccessful: TaskInstance;
/**
* The most recently completed task instance.
*/
readonly lastComplete: TaskInstance;
/**
* The most recent task instance that errored.
*/
readonly lastErrored: TaskInstance;
/**
* The most recently canceled task instance.
*/
readonly lastCanceled: TaskInstance;
/**
* The most recent task instance that is incomplete.
*/
readonly lastIncompleted: TaskInstance;
/**
* The number of times this task has been performed.
*/
readonly performCount: number;
readonly numRunning: number;
readonly numQueued: number;
/**
* alias for `numRunning`
*/
readonly concurrency: number;
readonly context: any;
readonly name: string;
perform(...args: any[]): TaskInstance;
/**
* Cancels all running or queued `TaskInstance`s for this Task.
* If you're trying to cancel a specific TaskInstance (rather
* than all of the instances running under this task) call
* `.cancel()` on the specific TaskInstance.
*/
cancelAll(): void;
}
}
declare module 'ember-concurrency/task-instance' {
import Task from 'ember-concurrency/task';
export enum TaskInstanceState {
/** task instance was canceled before it started */
DROPPED = 'dopped',
/** task instance was canceled before it could finish */
CANCELED = 'canceled',
/** task instance ran to completion (even if an exception was thrown) */
FINISHED = 'finished',
/** task instance is currently running (returns true even if is paused on a yielded promise) */
RUNNING = 'running',
/** task instance hasn't begun running yet (usually because the task is using the `TaskProperty#enqueue` task modifier) */
WAITING = 'waiting'
}
/**
* A `TaskInstance` represent a single execution of a
* `Task`. Every call to `Task#perform` returns
* a `TaskInstance`. `TaskInstance`s are cancelable, either explicitly
* via `TaskInstance#cancel` or `Task#cancelAll`,
* or automatically due to the host object being destroyed, or
* because concurrency policy enforced by a
* `TaskProperty` Modifier canceled the task instance.
*/
export default class TaskInstance {
/**
* If this TaskInstance runs to completion by returning a property
* other than a rejecting promise, this property will be set
* with that value.
*/
readonly value: any;
/**
* If this TaskInstance is canceled or throws an error (or yields
* a promise that rejects), this property will be set with that error.
* Otherwise, it is null.
*/
readonly error: any;
/**
* `true` if the task instance is fulfilled.
*/
readonly isSuccessful: boolean;
/**
* `true` if the task instance resolves to a rejection.
*/
readonly isError: boolean;
/**
* `true` if the task instance was canceled before it could run to completion.
*/
readonly isCanceled: boolean;
/**
* `true` if the task instance is canceling.
*/
readonly isCanceling: boolean;
/**
* `true` if the task instance has started, else false.
*/
readonly hasStarted: boolean;
/**
* `true` if the task has run to completion.
*/
readonly isFinished: boolean;
/**
* `true` if the task is still running.
*/
readonly isRunning: boolean;
/**
* Describes the state that the task instance is in. Can be used for debugging,
* or potentially driving some UI state. Possible values are:
*
* - `"dropped"`: task instance was canceled before it started
* - `"canceled"`: task instance was canceled before it could finish
* - `"finished"`: task instance ran to completion (even if an exception was thrown)
* - `"running"`: task instance is currently running (returns true even if is paused on a yielded promise)
* - `"waiting"`: task instance hasn't begun running yet (usually because the task is using the `TaskProperty#enqueue` task modifier)
*
* The animated timeline examples on the [Task Concurrency](http://ember-concurrency.com/docs/task-concurrency)
* docs page make use of this property.
*/
readonly state: TaskInstanceState;
task: Task;
cancel(reason?: string): void;
/**
* Returns a promise that resolves with the value returned
* from the task's (generator) function, or rejects with
* either the exception thrown from the task function, or
* an error with a `.name` property with value `"TaskCancelation"`.
*/
then(cb?: (value: any) => void): Promise<any>;
catch(cb?: (value: any) => void): Promise<any>;
finally(cb?: (value: any) => void): Promise<any>;
}
}