Promise.all vs allSettled vs any vs race in JavaScript (2026)

Header image: Promise.all in JavaScript, a large number 4 for the four promise combinators: all, allSettled, any and race.

Hey friends,

Promise.all runs several promises at once and fulfills with an array of every result, in input order, but rejects as soon as any one of them rejects. That's from MDN's Promise.all page. Its three siblings, allSettled, any and race, cover the cases where that all-or-nothing behavior isn't what you want.

Picking the right one is a classic scenario question in the Asynchronous Programming section of the Salesforce JavaScript Developer exam. Here's the comparison, then examples.

What's the difference between all, allSettled, any and race?

MethodFulfills whenRejects whenUse it for
Promise.allAll inputs fulfill. Value: array of results in input order.Any input rejects (with that first reason)Loading things you need all of
Promise.allSettledAll inputs settle, either way. Value: array of status objects.Never, for an iterable of promisesBatch work where you report each outcome
Promise.anyThe first input fulfillsAll inputs reject, with an AggregateErrorFastest successful source, like mirrors
Promise.raceThe first input to settle fulfillsThe first input to settle rejectsTimeouts

An empty array is the edge case: Promise.all and allSettled fulfill right away with [], and Promise.any rejects with an AggregateError.

How do you use Promise.all?

dashboard.js
1async function loadDashboard(id) {
2  const [account, contacts, cases] = await Promise.all([
3    getAccount(id),
4    getContacts(id),
5    getCases(id),
6  ]);
7  return { account, contacts, cases };
8}

The three calls start together, so the total time is about the slowest one, not the sum. Results come back in the order you passed them, no matter which finishes first. Non-promise values in the array are passed through as-is.

Important: when one rejects, Promise.all rejects, but the other operations keep running. JavaScript has no built-in way to cancel them. Their results are just ignored.

When should you use Promise.allSettled?

When partial success is fine and you want to know what happened to each one. Each result is an object with status of "fulfilled" and a value, or "rejected" and a reason.

syncAll.js
1const results = await Promise.allSettled(records.map((r) => syncRecord(r)));
2
3const failed = results.filter((r) => r.status === 'rejected');
4console.log(`${results.length - failed.length} synced, ${failed.length} failed`);
5failed.forEach((f) => console.error(f.reason.message));

Cert Lab by Nick Frates

Let the JavaScript Developer Cert Lab test you to success

Pick-the-right-API scenarios on promises, async/await and the rest of the exam, with an explanation for every option.

Start the JavaScript Developer Cert Lab for $9.99 →

Not ready to buy? Try a free lesson and see how fast you learn.

When should you use Promise.any?

When you need one success and don't care which. It ignores rejections until all of them have failed. Then it rejects with an AggregateError whose errors array holds every reason, in input order.

firstMirror.js
1try {
2  const data = await Promise.any([
3    fetchJson('https://mirror-a.example.com/data'),
4    fetchJson('https://mirror-b.example.com/data'),
5  ]);
6  render(data);
7} catch (e) {
8  console.error('All mirrors failed', e.errors);
9}

When should you use Promise.race?

When the first one to finish wins, success or failure. The classic use is a timeout:

timeout.js
1function withTimeout(promise, ms) {
2  const timer = new Promise((_, reject) =>
3    setTimeout(() => reject(new Error('Timed out')), ms)
4  );
5  return Promise.race([promise, timer]);
6}
7
8const res = await withTimeout(fetch('/api/slow'), 5000);

any vs race, the one the exam likes: if the first promise to settle rejects, race rejects, but any keeps waiting for a fulfillment.

What Promise.all mistakes should you avoid?

  • Passing functions instead of promises. Promise.all([getA, getB]) resolves to the functions themselves. Call them: [getA(), getB()].
  • Using all when one failure shouldn't sink the batch. Use allSettled.
  • Firing thousands of requests at once. Promise.all doesn't limit concurrency. Process in chunks.
  • Assuming a rejection cancels the rest. It doesn't.

Back to basics: JavaScript promises explained and async/await.

Quick backstory. I loved Focus on Force and used it on my way to 17 Salesforce certifications. At first I read the study guide cover to cover, then took the tests. What I eventually noticed: I learned way faster when I skipped ahead and took practice tests rapid-fire, reading the explanation for every miss. So I built Cert Lab around fast testing, with up-to-date doc links in every explanation. It's designed to test you to success.

FAQ

Does Promise.all run in parallel?

The operations run concurrently: they all start before any finishes. Your JavaScript callbacks still run one at a time on a single thread.

What order does Promise.all return results in?

Input order, regardless of which promise finishes first.

What happens if one promise in Promise.all rejects?

The returned promise rejects with that reason right away. The other operations keep going, but their results are ignored.

Which Promise method never rejects?

Promise.allSettled, when you give it an iterable of promises. See the JavaScript Developer study guide for the full async section.

Where should you go next?

Nick Frates, a senior Salesforce developer with 17 certifications, built the JavaScript Developer Cert Lab at nickfrates.com: rapid-fire practice questions for every exam section, each answer explained.

Cert Lab by Nick Frates

Let the JavaScript Developer Cert Lab test you to success

Lessons, flashcards, a quiz for each of the seven exam sections and full practice exams, every answer explained.

Start the JavaScript Developer Cert Lab for $9.99 →

Not ready to buy? Try a free lesson and see how fast you learn.

Hope this helps!

Best,

Nick

Keep reading

See all posts →

Salesforce Saturdays

Join 1,033 Salesforce pros getting one 10-minute tip on Salesforce tech or career growth every Saturday.