internal export type PromiseResolveFunc < T > = ( value : T | PromiseLike < T > ) => void ; internal export type PromiseRejectFunc = ( reason : any ) => void ; internal export class PromiseContainer < T > { private _resolve ! : PromiseResolveFunc < T > ; private _reject ! : PromiseRejectFunc ; private _internal : Promise < T > ; constructor ( ) { this . _internal = new Promise < T > ( ( resolve , reject ) => { this . _resolve = resolve ; this . _reject = reject ; } ) ; } public get promise ( ) : Promise < T > { return this . _internal ; } public resolve ( value ) { this . _resolve ( value ) ; } public reject ( reason ? ) { this . _reject ( reason ) ; } } internal export class ResolvablePromise < T > implements PromiseLike < T > { private _wrapped : Promise < T > ; private _resolve ! : ( value : T ) => void ; private _reject ! : ( msg ? : string ) => void ; public constructor ( ) { this . _wrapped = new Promise < T > ( ( resolve , reject ) => { this . _resolve = resolve ; this . _reject = reject ; } ) ; } public then < TResult1 = T , TResult2 = never > ( onfulfilled ? , onrejected ? ) { return this . _wrapped . then ( onfulfilled , onrejected ) ; } public async resolve ( result ) { this . _resolve ( result ) ; await new Promise < void > ( ( resolve ) => { setImmediate ( resolve ) ; } ) ; } public async reject ( msg ? ) { this . _reject ( msg ) ; await new Promise < void > ( ( resolve ) => { setImmediate ( resolve ) ; } ) ; } }