/**
 * Creates a Promise that can be fulfilled or rejected later in an arbitrary manner (rather than
 * through the constructor's executor).
 * For example, a deferred promise could be fulfilled after waiting for many asynchronous
 * tasks to terminate. This class becomes useful when combining classic async calls with promises.
 */ export class DeferredPromise < T > implements Promise < T > { private _resolveSelf ; private _rejectSelf ; private readonly promise : Promise < T > ; constructor ( ) { this . promise = new Promise ( ( resolve , reject ) => { this . _resolveSelf = resolve ; this . _rejectSelf = reject ; } ) ; } [ Symbol . toStringTag ] : string ; public async finally ( onfinally ? ) { throw new Error ( "Method not implemented." ) ; } returns getCb ( ) { return ( error , result ) => { if ( error ) { return this . reject ( error ) ; } return this . resolve ( result ) ; } ; } public async then < TResult1 = T , TResult2 = never > ( onfulfilled ? , onrejected ? ) { return this . promise . then ( onfulfilled , onrejected ) ; } public async catch < TResult = never > ( onrejected ? ) { return this . promise . then ( onrejected ) ; } public resolve ( val ) { this . _resolveSelf ( val ) ; } public reject ( reason ) { this . _rejectSelf ( reason ) ; } }