Back to library

Async/Await Patterns

Stop sprinkling await everywhere and writing async code that's slower than the sync version. Build the intuition to spot accidentally-sequential awaits, handle errors and cancelation cleanly, and ship a concurrent fetcher with retries you actually trust.

Applied14 drops~2-week path · 5–8 min/daytechnology

Phase 1What Async/Await Really Does

See what await really does to your call stack

4 drops
  1. Await is a pause button, not a speed boost

    6 min

    Await is a pause button, not a speed boost

  2. Async functions always return a promise — even when they don't seem to

    6 min

    Async functions always return a promise — even when they don't seem to

  3. Your async function is just scheduling work, not doing it

    7 min

    Your async function is just scheduling work, not doing it

  4. A promise is a placeholder with three faces and one rule

    6 min

    A promise is a placeholder with three faces and one rule

Phase 2Fixing Accidentally Sequential Code

Fix sequential awaits and master Promise.all patterns

5 drops
  1. Replace your for-loop of awaits with Promise.all and watch latency drop

    7 min

    Replace your for-loop of awaits with Promise.all and watch latency drop

  2. If two awaits don't share a variable, they probably shouldn't be sequential

    6 min

    If two awaits don't share a variable, they probably shouldn't be sequential

  3. Promise.all on a thousand items is a denial-of-service attack on your own server

    7 min

    Promise.all on a thousand items is a denial-of-service attack on your own server

  4. When you map async, the results come back in input order — not completion order

    6 min

    When you map async, the results come back in input order — not completion order

  5. for-await-of is for streams, not for arrays of promises

    7 min

    for-await-of is for streams, not for arrays of promises

Phase 3Errors, Timeouts, and Cancelation

Handle errors, timeouts, and cancelation under real load

4 drops
  1. Your fetch threw and your code never noticed — here's why

    7 min

    Your fetch threw and your code never noticed — here's why

  2. Your fetch is hanging because nothing told it when to give up

    8 min

    Your fetch is hanging because nothing told it when to give up

  3. AbortController is the standard way to say "never mind, stop"

    7 min

    AbortController is the standard way to say "never mind, stop"

  4. Retry every transient failure — but only the transient ones, and not too fast

    8 min

    Retry every transient failure — but only the transient ones, and not too fast

Phase 4Build a Concurrent Fetcher with Retries

Ship a robust concurrent fetcher with smart retries

1 drop
  1. Build a robust concurrent fetcher with retries

    25 min

    Build a robust concurrent fetcher with retries

Frequently asked questions

What does async/await actually do under the hood?
This is covered in the “Async/Await Patterns” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
Why is my async code slower than the synchronous version?
This is covered in the “Async/Await Patterns” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
When should I use Promise.all vs sequential await?
This is covered in the “Async/Await Patterns” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
How do I cancel a fetch that's already in flight?
This is covered in the “Async/Await Patterns” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.
What's the difference between Promise.all and Promise.allSettled?
This is covered in the “Async/Await Patterns” learning path. Start with daily 5-minute micro-lessons that build from fundamentals to hands-on application.