Created
July 14, 2024 19:34
-
-
Save chowey/254ce3e54978c22c3323603c6c017852 to your computer and use it in GitHub Desktop.
Promise.withResolvers polyfill
This file contains hidden or 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
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