Skip to content

Instantly share code, notes, and snippets.

@David200197
Last active January 8, 2025 21:22
Show Gist options
  • Select an option

  • Save David200197/dad04cd2f0e73f94ee8ce536931fc7ef to your computer and use it in GitHub Desktop.

Select an option

Save David200197/dad04cd2f0e73f94ee8ce536931fc7ef to your computer and use it in GitHub Desktop.
Promise Resolvers
type Resolve<T> = (value: T) => void;
type Reject = (reason?: any) => void;
export const promiseResolver = <T>() => {
let resolve: Resolve<T> = () => {};
let reject: Reject = () => {};
const promise = new Promise<T>((res, rej) => {
resolve = res;
reject = rej;
});
return { resolve, reject, promise };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment