Created
June 22, 2021 13:11
-
-
Save fed135/3338b3a8bbecb7487bf376036849598e to your computer and use it in GitHub Desktop.
Deferred Promise
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 function deferred<T>() { | |
let resolve: (value?: T | PromiseLike<T>) => void; | |
let reject: (reason?: any) => void; | |
const promise = new Promise<T>((res, rej) => { | |
resolve = res; | |
reject = rej; | |
}); | |
return { promise, resolve, reject }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment