UNPKG

parallel-universe

Version:

The set of async flow control structures and promise utils.

28 lines (26 loc) 640 B
/** * The promise that can be resolved externally. * * @template T The value that the promise is fulfilled with. */ class Deferred extends Promise { static get [Symbol.species]() { return Promise; } /** * Creates a new instance of {@link Deferred}. * * @template T The value that the promise is fulfilled with. */ constructor() { let resolve; let reject; super((resolveSuper, rejectSuper) => { resolve = resolveSuper; reject = rejectSuper; }); this.resolve = resolve; this.reject = reject; } } export { Deferred };