1. Concept library
  2. JavaScript & TypeScript
  3. Module 6: Async patterns and fetch

Concept

Promise.all and rejection

Promise.all runs several promises at once and resolves with all their values, or rejects as soon as one fails. Promise.allSettled waits for every outcome. Choosing between them is choosing how failure should behave.

What a session covers

The tutor works through these with you, in conversation and code. A session ends when you have shown them, not when a video does.

  1. Explain how Promise.all and Promise.allSettled differ when one promise fails
  2. Start several independent requests at once and collect their results
  3. Spot the sequential loop of awaits and rewrite it to run in parallel

In practice

A few lines that show Promise.all and rejection doing its job.

TypeScript
const [user, orders] = await Promise.all([
  loadUser("7"),
  loadOrders("7"),
]);                                   // typed as [User, Order[]]

const results = await Promise.allSettled(ids.map(loadUser));
const loaded = results
  .filter((r): r is PromiseFulfilledResult<User> => r.status === "fulfilled")
  .map((r) => r.value);

The common mistake

Watch for

Awaiting independent requests one after another in a loop. Each waits for the previous to finish, so five 200ms calls take a second instead of 200ms. Start them together and await Promise.all.

What to know first

Your roadmap puts these before Promise.all and rejection, unless you already know them.

How it stays learned

Once a session shows you understand Promise.all and rejection, it comes back for review. Each review takes a minute and tells the memory model how well you still know it.

  1. Day 3First recall, while it is fresh
  2. Day 7Second, a week on
  3. Day 18Last, when it has settled

The review card

What you are asked on review day.

JavaScript & TypeScript · Async patterns and fetch

What does Promise.all do when one promise rejects?

Show answer

It rejects immediately with that first reason. The other promises keep running but their results are discarded — use Promise.allSettled to collect every outcome.

Previous in the module← Promises and async/await
Next in the moduleTyped fetch responses →