Skip to content

Instantly share code, notes, and snippets.

@jrobinsonc
Last active November 23, 2023 18:53
Show Gist options
  • Save jrobinsonc/2076bd8959eb9326e9b4adf9666d5d19 to your computer and use it in GitHub Desktop.
Save jrobinsonc/2076bd8959eb9326e9b4adf9666d5d19 to your computer and use it in GitHub Desktop.
Promise Resolution with Resolver and Rejector
/**
* 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