Last active
April 19, 2023 21:57
-
-
Save codenickycode/70add30ec76d6ef1612e3873ac6e20f6 to your computer and use it in GitHub Desktop.
[TS: Deferred Promise] Create a promise and pass along its res and rej #typescript #javascript #promise
This file contains hidden or 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
// Andrew Burgess, YouTube | |
// https://www.youtube.com/watch?v=Yvhad4zdPqI | |
export class Deferred<T, E = unknown> { | |
promise: Promise<T>; | |
resolve: (value: T) => void = () => null; | |
reject: (reason?: E) => void = () => null; | |
constructor() { | |
this.promise = new Promise({resolve, reject} => { | |
this.resolve = resolve; | |
this.reject = reject; | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment