UNPKG

parallel-universe

Version:

The set of async flow control structures and promise utils.

30 lines (27 loc) 663 B
'use strict'; /** * 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; } } exports.Deferred = Deferred;