Skip to content

Instantly share code, notes, and snippets.

@wmakeev
Last active August 2, 2024 13:35
Show Gist options
  • Save wmakeev/4940da20c5a8c89f5c3f3b863fd5efb6 to your computer and use it in GitHub Desktop.
Save wmakeev/4940da20c5a8c89f5c3f3b863fd5efb6 to your computer and use it in GitHub Desktop.
[Promise with resolvers] #promise #helper
export function getPromiseWithResolvers() {
let resolve;
let reject;
const promise = new Promise((resolve_, reject_) => {
resolve = resolve_;
reject = reject_;
});
return { promise, resolve, reject };
}
export function getPromiseWithResolvers() {
let resolve: (value: unknown) => void;
let reject: (reason?: any) => void;
const promise = new Promise((resolve_, reject_) => {
resolve = resolve_;
reject = reject_;
});
return { promise, resolve: resolve!, reject: reject! };
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment