GoonCord/src/core/polyfills.ts
2024-03-06 01:57:59 +08:00

8 lines
547 B
TypeScript

//! Starting from 202.4, Promise.allSettled may be undefined due to conflicting then/promise versions, so we use our own.
const allSettledFulfill = <T>(value: T) => ({ status: "fulfilled", value });
const allSettledReject = <T>(reason: T) => ({ status: "rejected", reason });
const mapAllSettled = <T>(item: T) => Promise.resolve(item).then(allSettledFulfill, allSettledReject);
export const allSettled = <T extends unknown[]>(iterator: T) => Promise.all(Array.from(iterator).map(mapAllSettled));
// @ts-ignore
Promise.allSettled ??= allSettled;