UNPKG

1.44 kBTypeScriptView Raw
1/*! *****************************************************************************
2Copyright (c) Microsoft Corporation.
3Licensed under the Apache License, Version 2.0.
4
5See LICENSE file in the project root for details.
6***************************************************************************** */
7/**
8 * Encapsulates a Promise and exposes its resolve and reject callbacks.
9 */
10export declare class Deferred<T> {
11 private _promise;
12 private _resolve;
13 private _reject;
14 private _callback?;
15 /**
16 * Initializes a new instance of the Deferred class.
17 */
18 constructor();
19 /**
20 * Gets the promise.
21 */
22 get promise(): Promise<T>;
23 /**
24 * Gets the callback used to resolve the promise.
25 */
26 get resolve(): (value?: T | PromiseLike<T> | undefined) => void;
27 /**
28 * Gets the callback used to reject the promise.
29 */
30 get reject(): (reason: any) => void;
31 /**
32 * Gets a NodeJS-style callback that can be used to resolve or reject the promise.
33 */
34 get callback(): T extends void ? (err: Error | null | undefined) => void : (err: Error | null | undefined, value: T) => void;
35 /**
36 * Creates a NodeJS-style callback that can be used to resolve or reject the promise with multiple values.
37 */
38 createCallback<A extends any[]>(selector: (...args: A) => T): (err: Error | null | undefined, ...args: A) => void;
39}