/
index.d.ts
51 lines (45 loc) · 1.48 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
/// <reference lib="dom"/>
export interface ClearablePromise<T> extends Promise<T> {
/**
* Clears the delay and settles the promise.
*/
clear(): void;
}
export interface Options {
/**
* An optional AbortSignal to abort the delay.
* If aborted, the Promise will be rejected with an AbortError.
*/
signal?: AbortSignal
}
declare const delay: {
/**
* Create a promise which resolves after the specified `milliseconds`.
*
* @param milliseconds - Milliseconds to delay the promise.
* @returns A promise which resolves after the specified `milliseconds`.
*/
(milliseconds: number, options?: Options): ClearablePromise<void>;
/**
* Create a promise which resolves after the specified `milliseconds`.
*
* @param milliseconds - Milliseconds to delay the promise.
* @returns A promise which resolves after the specified `milliseconds`.
*/
<T>(milliseconds: number, options?: Options & {
/** Value to resolve in the returned promise. */
value: T
}): ClearablePromise<T>;
/**
* Create a promise which rejects after the specified `milliseconds`.
*
* @param milliseconds - Milliseconds to delay the promise.
* @returns A promise which rejects after the specified `milliseconds`.
*/
// TODO: Allow providing value type after https://github.com/Microsoft/TypeScript/issues/5413 will be resolved.
reject(milliseconds: number, options?: Options & {
/** Value to reject in the returned promise. */
value?: any
}): ClearablePromise<never>;
};
export default delay;