UNPKG

openai

Version:

The official TypeScript library for the OpenAI API

29 lines • 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.allSettledWithThrow = void 0; /** * Like `Promise.allSettled()` but throws an error if any promises are rejected. * Rejection reasons remain available on the thrown error's non-enumerable `rejections` * property without being written to the global console. */ const allSettledWithThrow = async (promises) => { const results = await Promise.allSettled(promises); const rejected = results.filter((result) => result.status === 'rejected'); if (rejected.length) { throw Object.defineProperty(new Error(`${rejected.length} promise(s) failed`), 'rejections', { configurable: true, value: rejected.map(({ reason }) => reason), writable: true, }); } // Note: TS was complaining about using `.filter().map()` here for some reason const values = []; for (const result of results) { if (result.status === 'fulfilled') { values.push(result.value); } } return values; }; exports.allSettledWithThrow = allSettledWithThrow; //# sourceMappingURL=Util.js.map