allfulfilled
v0.1.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 map all rejection reasons to a single Error. Defaults to aggregate, which
wraps 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());
//=> ErrorReasonsErrorMapper(reasons)
Maps all reasons that any Promise was rejected with to a single Error.
A ReasonsErrorMapper is only called with a non-empty array of reasons.
There are a several ReasonsErrorMapper function providers built-in.
aggregate([message])
Returns a ReasonsErrorMapper that wraps all the reasons a Promise was rejected with into an AggregateError.
Optionally, message can be specified for the AggregateError.
first([toError])
Returns a ReasonsErrorMapper 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 ReasonsErrorMapper 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.
