UNPKG

promise-settle-all

Version:

Promise.all function that waits for all promises to be settled

25 lines 887 B
"use strict"; exports.__esModule = true; var CombinedError = require("combine-errors"); /** * Similar to Promise.all, but unlike Promise.all, will not reject as soon as any * of the given promises is rejected, but will wait for all of the given promises * to be settled. * * @param {Iterable<PromiseLike<TAll> | TAll>} promises * @returns {Promise<TAll[]>} * @throws A combined error containing all rejected promises */ function allSettled(promises) { var errors = []; return Promise.all(Array.from(promises).map(function (promise) { return Promise.resolve(promise)["catch"](function (err) { return (errors.push(err), undefined); }); })).then(function (result) { if (errors.length) { throw CombinedError(errors); } else { return result; } }); } exports["default"] = allSettled; //# sourceMappingURL=index.js.map