allfulfilled
v0.2.0
Published
Use Promise.allSettled like Promise.all
Readme
allfulfilled
allfulfilled is a Node.js package for using Promise.allSettled like Promise.all.
Install
Install using npm:
npm install --save allfulfilledUsage
allFulfilled(promises[, toError])
Returns a new Promise that is fulfilled with an array of fulfillment values when all the specified promises are
fulfilled, or rejected with an Error if any of promises are rejected.
This function behaves similarly to Promise.all but uses Promise.allSettled internally to collect all rejection
reasons before rejecting with a single Error.
Optionally, toError can be specified to reduce all rejection reasons to a single Error. Defaults to aggregate,
which reduces all rejection reasons into an AggregateError.
Examples
import { allFulfilled, first } from "allfulfilled";
await allFulfilled([Promise.resolve(1), Promise.resolve("2"), Promise.resolve(3)]);
//=> [1, "2", 3]
await allFulfilled([Promise.resolve(1), Promise.reject(new Error("Oops")), Promise.resolve(3)]);
//=> AggregateError
await allFulfilled([Promise.resolve(1), Promise.reject(new Error("Oops")), Promise.resolve(3)], first());
//=> ErrorReasonsErrorReducer(reasons)
Reduces all reasons that any Promise was rejected with to a single Error.
A ReasonsErrorReducer is only called with a non-empty array of reasons.
There are a several ReasonsErrorReducer function providers built-in.
aggregate([message])
Returns a ReasonsErrorReducer that reduces all the reasons a Promise was rejected with into an AggregateError.
Optionally, message can be specified for the AggregateError.
any([toError])
Returns a ReasonsErrorReducer that returns any reason a Promise was rejected with as an Error, with a preference
of using the first reason that is an Error to avoid calling toError, if specified.
If toError is specified and the every reason is not an Error, toError will be used to map the first reason to
an Error.
first([toError])
Returns a ReasonsErrorReducer that returns the first reason a Promise was rejected with as an Error.
If toError is specified and the first reason is not an Error, toError will be used to map the first reason to
an Error.
last([toError])
Returns a ReasonsErrorReducer that returns the last reason a Promise was rejected with as an Error.
If toError is specified and the last reason is not an Error, toError will be used to map the last reason to an
Error.
Bugs
If you have any problems with this package or would like to see changes currently in development, you can do so here.
Contributors
If you want to contribute, you're a legend! Information on how you can do so can be found in CONTRIBUTING.md. We want your suggestions and pull requests!
A list of all contributors can be found in AUTHORS.md.
License
Copyright © 2026 neocotic
See LICENSE.md for more information on our MIT license.
