Created
November 23, 2020 14:20
-
-
Save NickBolles/bce9e13faa8c6c2b6ce61b4430a392d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export class ResolvablePromise<T = any> implements Promise<T> { | |
[Symbol.toStringTag]: string; | |
__promise: Promise<T>; | |
resolve!: (value: T) => void; | |
reject!: (reason: T) => void; | |
constructor() { | |
this.__promise = new Promise<T>((resolve, reject) => { | |
this.resolve = resolve; | |
this.reject = reject; | |
}); | |
} | |
then<TResult1 = T, TResult2 = never>( | |
onfulfilled?: (value: T) => TResult1 | PromiseLike<TResult1>, | |
onrejected?: (reason: any) => TResult2 | PromiseLike<TResult2> | |
): Promise<TResult1 | TResult2> { | |
return this.__promise.then(onfulfilled, onrejected); | |
} | |
catch(...args: any[]) { | |
return this.__promise.catch(...args); | |
} | |
finally(...args: any[]) { | |
return this.__promise.finally(...args); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment