JavaScript theorytheory 0/50 · 0%
Async · easy

13. Promises

States, then/catch/finally and combinators.

A promise is pending, then either fulfilled or rejected — once, permanently. `then` chains, `catch` handles rejection and `finally` always runs.

Promise.all([a, b]);           // rejects on the first failure
Promise.allSettled([a, b]);    // never rejects; reports each outcome
Promise.race([a, timeout]);    // first to settle wins

`Promise.all` is the right tool for parallel RPC reads; `race` with a timer gives you a timeout.

Check your understanding

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

  2. 2. Which combinator never rejects?

  3. 3. How do you add a timeout to a request?