prex
Version:
Async coordination primitives and extensions on top of ES6 Promises
40 lines (38 loc) • 1.44 kB
TypeScript
/*! *****************************************************************************
Copyright (c) Microsoft Corporation.
Licensed under the Apache License, Version 2.0.
See LICENSE file in the project root for details.
***************************************************************************** */
/**
* Encapsulates a Promise and exposes its resolve and reject callbacks.
*/
export declare class Deferred<T> {
private _promise;
private _resolve;
private _reject;
private _callback?;
/**
* Initializes a new instance of the Deferred class.
*/
constructor();
/**
* Gets the promise.
*/
get promise(): Promise<T>;
/**
* Gets the callback used to resolve the promise.
*/
get resolve(): (value?: T | PromiseLike<T> | undefined) => void;
/**
* Gets the callback used to reject the promise.
*/
get reject(): (reason: any) => void;
/**
* Gets a NodeJS-style callback that can be used to resolve or reject the promise.
*/
get callback(): T extends void ? (err: Error | null | undefined) => void : (err: Error | null | undefined, value: T) => void;
/**
* Creates a NodeJS-style callback that can be used to resolve or reject the promise with multiple values.
*/
createCallback<A extends any[]>(selector: (...args: A) => T): (err: Error | null | undefined, ...args: A) => void;
}