Last active
November 23, 2023 18:53
-
-
Save jrobinsonc/2076bd8959eb9326e9b4adf9666d5d19 to your computer and use it in GitHub Desktop.
Promise Resolution with Resolver and Rejector
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 that returns a promise along with resolver and rejector functions | |
* | |
* @template T The type of the resolved value | |
* @returns {{ promise: Promise<T>, resolver: (arg: T) => void, rejector: (error: Error) => void }} | |
*/ | |
const PromiseResolution = <T>() => { | |
let resolver!: (arg: T) => void; | |
let rejector!: (error: Error) => void; | |
const promise: Promise<T> = new Promise<T>((resolve, reject) => { | |
resolver = resolve; | |
rejector = reject; | |
}); | |
return { | |
promise, | |
resolver, | |
rejector | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment