1 | export interface DeferredPromise<ValueType> {
|
2 | /**
|
3 | The deferred promise.
|
4 | */
|
5 | promise: Promise<ValueType>;
|
6 |
|
7 | /**
|
8 | Resolves the promise with a value or the result of another promise.
|
9 |
|
10 | @param value - The value to resolve the promise with.
|
11 | */
|
12 | resolve(value?: ValueType | PromiseLike<ValueType>): void;
|
13 |
|
14 | /**
|
15 | Reject the promise with a provided reason or error.
|
16 |
|
17 | @param reason - The reason or error to reject the promise with.
|
18 | */
|
19 | reject(reason?: unknown): void;
|
20 | }
|
21 |
|
22 | /**
|
23 | Create a deferred promise.
|
24 |
|
25 | @example
|
26 | ```
|
27 | import pDefer from 'p-defer';
|
28 |
|
29 | function delay(milliseconds) {
|
30 | const deferred = pDefer();
|
31 | setTimeout(deferred.resolve, milliseconds, '🦄');
|
32 | return deferred.promise;
|
33 | }
|
34 |
|
35 | console.log(await delay(100));
|
36 | //=> '🦄'
|
37 | ```
|
38 | */
|
39 | export default function pDefer<ValueType>(): DeferredPromise<ValueType>;
|