Skip to content

Instantly share code, notes, and snippets.

@chowey
Created July 14, 2024 19:34
Show Gist options
  • Save chowey/254ce3e54978c22c3323603c6c017852 to your computer and use it in GitHub Desktop.
Save chowey/254ce3e54978c22c3323603c6c017852 to your computer and use it in GitHub Desktop.
Promise.withResolvers polyfill
Promise.withResolvers ??
(Promise.withResolvers = function withResolvers<T>() {
let a: (value: T | PromiseLike<T>) => void;
let b: (reason?: unknown) => void;
const c = new this<T>(function (resolve, reject) {
a = resolve;
b = reject;
});
return { resolve: a!, reject: b!, promise: c };
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment