1 | import { Disposable } from './disposable';
|
2 | import { Event } from './event';
|
3 | import { CancellationToken } from './cancellation';
|
4 | /**
|
5 | * Simple implementation of the deferred pattern.
|
6 | * An object that exposes a promise and functions to resolve and reject it.
|
7 | */
|
8 | export declare class Deferred<T = void> {
|
9 | state: 'resolved' | 'rejected' | 'unresolved';
|
10 | resolve: (value: T | PromiseLike<T>) => void;
|
11 | reject: (err?: unknown) => void;
|
12 | promise: Promise<T>;
|
13 | protected setState(state: 'resolved' | 'rejected'): void;
|
14 | }
|
15 | /**
|
16 | * @returns resolves after a specified number of milliseconds
|
17 | * @throws cancelled if a given token is cancelled before a specified number of milliseconds
|
18 | */
|
19 | export declare function timeout(ms: number, token?: CancellationToken): Promise<void>;
|
20 | /**
|
21 | * Creates a promise that is rejected after the given amount of time. A typical use case is to wait for another promise until a specified timeout using:
|
22 | * ```
|
23 | * Promise.race([ promiseToPerform, timeoutReject(timeout, 'Timeout error message') ]);
|
24 | * ```
|
25 | *
|
26 | * @param ms timeout in milliseconds
|
27 | * @param message error message on promise rejection
|
28 | * @returns rejection promise
|
29 | */
|
30 | export declare function timeoutReject<T>(ms: number, message?: string): Promise<T>;
|
31 | export declare function retry<T>(task: () => Promise<T>, retryDelay: number, retries: number): Promise<T>;
|
32 | /**
|
33 | * A function to allow a promise resolution to be delayed by a number of milliseconds. Usage is as follows:
|
34 | *
|
35 | * `const stringValue = await myPromise.then(delay(600)).then(value => value.toString());`
|
36 | *
|
37 | * @param ms the number of millisecond to delay
|
38 | * @returns a function that returns a promise that returns the given value, but delayed
|
39 | */
|
40 | export declare function delay<T>(ms: number): (value: T) => Promise<T>;
|
41 | /**
|
42 | * Constructs a promise that will resolve after a given delay.
|
43 | * @param ms the number of milliseconds to wait
|
44 | */
|
45 | export declare function wait(ms: number): Promise<void>;
|
46 | export declare function waitForEvent<T>(event: Event<T>, ms: number, thisArg?: any, disposables?: Disposable[]): Promise<T>;
|
47 | export declare function isThenable<T>(obj: unknown): obj is Promise<T>;
|
48 | //# sourceMappingURL=promise-util.d.ts.map |
\ | No newline at end of file |