@worker-tools/middleware
Version:
A suite of standalone HTTP server middlewares for Worker Runtimes.
21 lines • 863 B
JavaScript
import { AggregateError } from "./aggregate-error.js";
export const isFulfilled = (r) => {
return r.status === 'fulfilled';
};
export const isRejected = (r) => {
return r.status === 'rejected';
};
/**
* Helper function that unwinds `Promise.allSettled`:
* Takes the promise returned and throws a `AggregateError` iff at least one promise settled with a rejection.
* Otherwise returns the list of fulfilled values.
* @param allSettledPromise A promise returned by `Promise.allSettled`
* @returns List of fulfilled values
*/
export const unsettle = async (allSettledPromise) => {
const rs = await allSettledPromise;
if (rs.every(isFulfilled))
return rs.map(r => r.value);
throw new AggregateError(rs.filter(isRejected).map(r => r.reason), "One or more Promises in 'unsettle' were rejected");
};
//# sourceMappingURL=unsettle.js.map