Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
FREEDOM251

Freedom251 › Blog › JavaScript

Promise.allSettled() vs. Promise.any() vs. Promise.race(): Which Should You Use?

By Freedom251 Team · · 3 min read

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use Promise.allSettled() when you need every operation to finish and want a report of each success or failure. Use Promise.any() when the first successful result is enough. Use Promise.race() when the first outcome of any kind—fulfillment or rejection—should settle the combined promise. None of these methods cancels unfinished work.

At a glance: what each combinator waits for

Method When the combined promise settles What it fulfills with What rejection does Best fit
Promise.allSettled(iterable) After every input settles An array of outcome records, one per input Individual rejections appear as records; the combined promise ordinarily fulfills Independent tasks where you need a complete success-and-failure report
Promise.any(iterable) At the first fulfillment, or after every input rejects The value from the first fulfilled input Rejects with an AggregateError if all inputs reject Redundant alternatives where any successful result is acceptable
Promise.race(iterable) As soon as the first input settles, fulfilled or rejected The fulfillment value of the first settled input Rejects with the first settled input’s rejection reason First-outcome behavior, such as a timeout race

All three methods accept an iterable, and values or thenables in it are handled by the promise machinery. The distinction to keep straight is that settled means fulfilled or rejected, while fulfilled means successful. See MDN’s references for Promise.allSettled(), Promise.any(), and Promise.race().

As an Amazon Associate I earn from qualifying purchases.

Choose by the outcome your caller needs

Use Promise.allSettled() for a complete outcome report

Choose allSettled() when tasks can succeed or fail independently and the caller needs to inspect every result. The aggregate waits for all inputs, then fulfills with records whose status is either "fulfilled" or "rejected".

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const outcomes = await Promise.allSettled(tasks);
const failures = outcomes.filter((result) => result.status === "rejected");

Check status before reading the corresponding field: fulfilled records contain value, while rejected records contain reason. This makes it possible to report partial failure without discarding successful outcomes.

Use Promise.any() when the first success wins

any() does not return the first promise to finish; it returns the value from the first one to fulfill. An earlier rejection does not prevent another input from succeeding.

const bestAvailable = await Promise.any([
  primary(),
  backupA(),
  backupB()
]);

If every input rejects, any() rejects with an AggregateError containing the rejection reasons. Handle that case when no available alternative is itself an acceptable outcome.

Use Promise.race() when the first settlement wins

race() settles with whichever input settles first. That may be a fulfillment or a rejection, so a quick failure can beat a slower success.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
const response = await Promise.race([fetch(url), timeoutPromise]);

This picks the first outcome for the wrapper promise; it does not stop the other input. MDN Web Docs describes Promise.race() as one of the promise concurrency methods in its JavaScript reference.

How this differs from Promise.all()

Use Promise.all() when all results are needed and any input rejection should reject the combined promise. Use Promise.allSettled() when all inputs should finish but you need both fulfilled and rejected outcomes in the returned array. They both wait for all inputs before successful completion; their main difference is how individual rejections affect the aggregate result. See MDN’s Promise reference.

What happens with an empty iterable?

Method Result for an empty iterable
Promise.allSettled([]) Fulfills with an empty array
Promise.any([]) Rejects with an AggregateError
Promise.race([]) Remains pending indefinitely

Cancellation and timeout pitfalls

These combinators determine how the aggregate promise responds; they do not start all work in parallel by themselves, nor do they cancel work that is still running. Inputs may already be running when passed to a combinator. In a timeout race, for example, the timeout winning does not automatically stop the fetch, and the fetch winning does not automatically clear the timer.

For fetch, use AbortController when you need to abort the request if the timeout wins, and clear the timer if the fetch wins. The cancellation and cleanup must be implemented separately from Promise.race().

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

A practical decision rule

  • Need every success and failure after all work finishes? Choose Promise.allSettled().
  • Need one successful result, while tolerating failed alternatives? Choose Promise.any().
  • Need the first result of any kind, including the first failure? Choose Promise.race().

These are language-semantics differences, not performance guarantees; actual completion order depends on the operations you pass in. The methods’ normative definitions are in Ecma International’s ECMA-262, 14th edition (June 2023).

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

JavaScriptPromisesWeb development

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.