Add Promise.withResolvers Polyfill
pckilgore opened this issue · 2 comments
pckilgore commented
What
Missing Promise.withResolvers
Details
react-pdf recently upgraded and no longer includes a polyfill for this API, which is now baseline available in 2024.
We've got some older safari clients breaking.
Happy to make a PR:
ref: CoreJS Polyfill
Code roughly:
if (typeof Promise.withResolvers === 'undefined') {
window.Promise.withResolvers = function () {
let resolve, reject;
const promise = new Promise((res, rej) => {
resolve = res;
reject = rej;
});
return { promise, resolve, reject };
}
}
Daniel15 commented
Your suggested polyfill isn't compliant as it doesn't handle subclassing:
Promise.withResolvers() is generic and supports subclassing, which means it can be called on subclasses of Promise, and the result will contain a promise of the subclass type.
pckilgore commented
There is a corejs example I provided if you need help implementing to spec. This is an issue report not a PR or an implementation plan.
…On Thu, Jul 18, 2024, at 8:52 PM, Daniel Lo Nigro wrote:
Your suggested polyfill isn't compliant as it doesn't handle subclassing:
> Promise.withResolvers() is generic and supports subclassing, which means it can be called on subclasses of Promise, and the result will contain a promise of the subclass type.
>
—
Reply to this email directly, view it on GitHub <#2886 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AATQYQ4CLUXNF52B4WB2QTLZNBWNBAVCNFSM6AAAAABJJFX2CKVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDEMZXHA3TMNJRGE>.
You are receiving this because you authored the thread.Message ID: ***@***.***>