forked from DefinitelyTyped/DefinitelyTyped
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhen.d.ts
65 lines (57 loc) · 2.72 KB
/
when.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
// Type definitions for When 2.4.0
// Project: https://github.com/cujojs/when
// Definitions: https://github.com/borisyankov/DefinitelyTyped
declare module When {
/**
* Return a promise that will resolve only once all the supplied promisesOrValues
* have resolved. The resolution value of the returned promise will be an array
* containing the resolution values of each of the promisesOrValues.
* @memberOf when
*
* @param promisesOrValues array of anything, may contain a mix
* of {@link Promise}s and values
*/
function all<T>(promisesOrValues: any[]): Promise<T>;
/**
* Creates a {promise, resolver} pair, either or both of which
* may be given out safely to consumers.
* The resolver has resolve, reject, and progress. The promise
* has then plus extended promise API.
*/
function defer<T>(): Deferred<T>;
/**
* Joins multiple promises into a single returned promise.
* @return a promise that will fulfill when *all* the input promises
* have fulfilled, or will reject when *any one* of the input promises rejects.
*/
function join<T>(...promises: Promise<T>[]): Promise<T[]>;
/**
* Joins multiple promises into a single returned promise.
* @return a promise that will fulfill when *all* the input promises
* have fulfilled, or will reject when *any one* of the input promises rejects.
*/
function join<T>(...promises: any[]): Promise<T[]>;
/**
* Returns a resolved promise. The returned promise will be
* - fulfilled with promiseOrValue if it is a value, or
* - if promiseOrValue is a promise
* - fulfilled with promiseOrValue's value after it is fulfilled
* - rejected with promiseOrValue's reason after it is rejected
*/
function resolve<T>(promise: Promise<T>): Promise<T>;
function resolve<T>(value?: T): Promise<T>;
interface Deferred<T> {
notify(update: any): void;
promise: Promise<T>;
reject(reason: any): void;
resolve(value?: T): void;
resolve(value?: Promise<T>): void;
}
interface Promise<T> {
ensure(onFulfilledOrRejected: Function): Promise<T>;
then<U>(onFulfilled: (value: T) => Promise<U>, onRejected?: (reason: any) => Promise<U>, onProgress?: (update: any) => void): Promise<U>;
then<U>(onFulfilled: (value: T) => Promise<U>, onRejected?: (reason: any) => U, onProgress?: (update: any) => void): Promise<U>;
then<U>(onFulfilled: (value: T) => U, onRejected?: (reason: any) => Promise<U>, onProgress?: (update: any) => void): Promise<U>;
then<U>(onFulfilled: (value: T) => U, onRejected?: (reason: any) => U, onProgress?: (update: any) => void): Promise<U>;
}
}