Batch independent tasks
Run independent API requests or background operations while retaining both successful and failed outcomes.
JavaScript · Function
Promise.allSettled() waits for every input promise to settle and fulfills with an input-ordered array describing each result. It reports both successes and failures instead of rejecting because one input failed.
Call Promise.allSettled with an iterable of values such as promises. It converts the values to promises, waits until every input is fulfilled or rejected, and fulfills with outcome records in input order. Each record identifies its state with status and carries either value or reason.
Promise.allSettled(iterable)| Name | Type | Description |
|---|---|---|
iterable | Iterable | An iterable, such as an Array, whose elements may be promises, thenables, or non-promise values. |
A Promise that fulfills with an array of outcome objects after all inputs settle. An empty iterable yields an already-fulfilled promise; a non-empty iterable with no pending promises fulfills asynchronously.
const results = await Promise.allSettled([
fetch("/api/profile"),
fetch("/api/recommendations"),
]);
for (const result of results) {
if (result.status === "fulfilled") {
console.log("Success:", result.value.status);
} else {
console.error("Failed:", result.reason);
}
}Runs independent requests together, then handles each outcome by checking its discriminating status field.
Run independent API requests or background operations while retaining both successful and failed outcomes.
Collect per-item results when some operations may fail without preventing the rest from completing.
Inspect every operation after a batch finishes for logging, metrics, or user-facing status reporting.
It returns one promise that fulfills after every input has settled, whether the individual inputs fulfilled or rejected. Its result is an array ordered like the input, and each item reports status plus either value or reason.
Follow-up: How does it differ from Promise.all()? Promise.all() rejects as soon as an input rejects, whereas allSettled() waits for every input and reports all outcomes.
The iterable can contain promises, thenables, or ordinary values. Values are awaited through promise resolution, while non-thenables become fulfilled outcomes with their values.
Follow-up: What happens for an empty iterable? The returned promise is already fulfilled with an empty array.
A fulfilled record has status set to "fulfilled" and a value property. A rejected record has status set to "rejected" and a reason property, so status should be checked before reading the corresponding field.
Follow-up: Does completion order affect the result order? No; records remain in the order of the original iterable.
Promise.all()Promise.any()Promise.race()Promise