1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-11-24 20:06:55 +01:00
unleash.unleash/src/lib/util/allSettledWithRejection.ts

17 lines
521 B
TypeScript

export const allSettledWithRejection = (
promises: Promise<any>[],
): Promise<any[]> =>
new Promise((resolve, reject) => {
Promise.allSettled(promises).then((results) => {
for (const result of results) {
if (result.status === 'rejected') {
reject(result.reason);
return;
}
}
resolve(
results.map((r) => (r as PromiseFulfilledResult<any>).value),
);
});
});