← Back to JavaScript
39

Use `Promise.all`, `allSettled`, `race` and `any` with intent

Coordinate multiple asynchronous tasks with the right promise combinator depending on whether you need total success, partial resilience, the fastest result or the first successful answer.

📘 Theory

Start from the contract, not the syntax

Before you write the code, decide what should happen when one task fails or arrives first.

Real products often launch several requests together: profile, permissions, notifications, charts, metrics or search suggestions.

The key question is not only how to run them, but how much of the interface should depend on all of them succeeding.

1

Promise.all

Everything must succeed or the whole flow fails.

2

Promise.allSettled

You always get every result and can degrade partially.

3

Promise.race

The first settled promise wins, whether it succeeds or fails.

4

Promise.any

The first successful promise wins, and rejections are ignored until all fail.

Use `Promise.all()` when the screen needs everything

This is a fail-fast contract for critical combined data.

1

`Promise.all()` preserves the input order in its final array even if the promises settle in a different order.

2

If one promise rejects, the whole combined promise rejects. That is useful when the view does not make sense with incomplete data.

Use `Promise.allSettled()` for partial resilience

If one widget can fail without killing the whole dashboard, this combinator is often the better fit.

1

Instead of one global success or failure, you receive an array of result objects with `status` and either `value` or `reason`.

2

That lets you render successful modules and degrade or hide only the failed ones.

🧪 Learn by doing

Example Guided example: true parallel loading with `Promise.all()` Compare the total duration when independent asynchronous tasks run together.
Example Interactive demo: compare `all`, `allSettled`, `race` and `any` Trigger simulated async tasks and see how the final result changes depending on the combinator.

🏁 Challenges

Challenge Challenge: load critical dashboard data with `Promise.all()` Combine two mandatory async calls and return one object ready for the UI.

What is this?

I'm Cristian Eslava and I sometimes build websites so both you and I can learn and experiment. culTest

I made this in February 2026 to make learning easier for my students. The idea is to learn web development by practicing and to keep expanding the project with new topics, tests and challenges.

It draws inspiration from MDN, W3Schools, CodePen, Manz and many other web development references. I wanted to combine useful theory, runnable examples, challenges and the testing system I had already built for culTest. culTest

If you liked it, if you didn't, or if you want to get in touch, write to me at cristianeslava@gmail.com