Polyfill Promise.withResolvers

Fixes: https://gitlab.com/soapbox-pub/soapbox/-/issues/1802
This commit is contained in:
Alex Gleason 2024-12-27 12:14:24 -06:00
parent 39065bc1af
commit 715c961fff
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 16 additions and 0 deletions

View File

@ -1,3 +1,5 @@
import 'soapbox/polyfill/Promise.withResolvers.ts';
import { enableMapSet } from 'immer'; import { enableMapSet } from 'immer';
import { createRoot } from 'react-dom/client'; import { createRoot } from 'react-dom/client';

View File

@ -0,0 +1,14 @@
if (!Promise.withResolvers) {
Promise.withResolvers = function withResolvers<T>(): PromiseWithResolvers<T> {
let resolve: (value: T | PromiseLike<T>) => void;
let reject: (reason?: any) => void;
const promise = new this<T>((_resolve, _reject) => {
resolve = _resolve;
reject = _reject;
});
return { resolve: resolve!, reject: reject!, promise };
};
}