Created
December 12, 2023 20:13
-
-
Save manbearwiz/571f97eb82ad9a10f4ba8afda15fdb2b 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
function generateDeferredPromise<T>(): { | |
promise: Promise<T>; | |
reject: (reason?: unknown) => void; | |
resolve: (value: T | PromiseLike<T>) => void; | |
} { | |
let resolve!: (value: T | PromiseLike<T>) => void; | |
let reject!: (reason?: unknown) => void; | |
const promise = new Promise<T>((res, rej) => { | |
[resolve, reject] = [res, rej]; | |
}); | |
return { promise, reject, resolve }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment