promise-settled-aggregate

Works like Promise.allSettled except it will reject with an AggregateError if some of the promises rejected, otherwise resolves with the fulfilled values.

Usage no npm install needed!

<script type="module">
  import promiseSettledAggregate from 'https://cdn.skypack.dev/promise-settled-aggregate';
</script>

README

promise-settled-aggregate

Creates a Promise that is resolved after all of the input Promises have either fulfilled or rejected, with an array of the results if all of the provided Promises resolve, or rejected with an AggregateError if some Promises rejected.

It works like Promise.allSettled except it will reject with an AggregateError if some of the promises are rejected, otherwise it resolves with the fulfilled values like Promise.all.

try {
  const [a, b, c, d] = await promiseSettledAggregate([
    Promise.reject(new Error("Boom")),
    Promise.resolve(2),
    Promise.resolve(true),
    Promise.reject(new Error("Pow")),
  ]);
} catch (err) {
  err.errors.forEach(console.error);
}

You may copy the source code (see dist for JS) directly into your project as this library is published under the Unlicense license.

You can also install from npm registry (npm install promise-settled-aggregate).