Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stefee/promise-settled-aggregate
Await an array of promises to be settled, then reject with an AggregateError upon failure, or resolve with an array of values upon success.
https://github.com/stefee/promise-settled-aggregate
aggregate aggregateerror allsettled promise promises reject settled
Last synced: 19 days ago
JSON representation
Await an array of promises to be settled, then reject with an AggregateError upon failure, or resolve with an array of values upon success.
- Host: GitHub
- URL: https://github.com/stefee/promise-settled-aggregate
- Owner: stefee
- License: unlicense
- Created: 2021-08-15T12:21:29.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2022-03-05T19:30:43.000Z (almost 3 years ago)
- Last Synced: 2024-12-09T04:05:07.860Z (25 days ago)
- Topics: aggregate, aggregateerror, allsettled, promise, promises, reject, settled
- Language: TypeScript
- Homepage:
- Size: 4.13 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# promise-settled-aggregate
> Await an array of promises to be settled, then reject with an AggregateError upon failure, or resolve with an array of values upon success.
It works like [Promise.allSettled](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/allSettled) except it will reject with an [AggregateError](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/AggregateError) if some of the promises are rejected, otherwise it resolves with the fulfilled values like [Promise.all](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all).
```js
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](https://github.com/stefee/promise-settled-aggregate/blob/main/promiseSettledAggregate.ts) (see [dist](./dist) for JS) directly into your project as this library is published under the Unlicense license.
You can also install it as a npm dependency:
```
npm install promise-settled-aggregate
```