JavaScript theorytheory 0/50 · 0%
Async · medium

28. Promises in depth

States, chaining and combinators.

A promise is pending, fulfilled or rejected, and settles once. `then` returns a new promise, so chains flatten. Combinators run work concurrently: `all` fails fast, `allSettled` reports every outcome, `race` takes the first to settle.

const [a, b] = await Promise.all([getBlock(), getGas()]);

Sequential `await`s in a loop are the most common cause of a slow dApp — batch independent calls.

Check your understanding

  1. 1. How many times can a promise settle?

  2. 2. Which combinator never rejects?

  3. 3. How do you speed up independent async calls?