New: Try Voli The Bear, Fast package manager (and not only) for Windows
All topics / Async/Await & the Event Loop

Async/Await & the Event Loop

Async exists because programs spend most of their time waiting; the event loop is a single thread plus a queue of ready-to-continue work; and async/await is just readable syntax over 'a value that isn't here yet.'

Download EPUB
  1. Why Async Exists A huge fraction of programming is waiting - on the network, the disk, a timer. Blocking stops the worker dead while it waits; non-blocking starts the wait, does other useful work, and comes back when the result is ready.
  2. The Event Loop The event loop is a single thread running your code plus a queue of 'things ready to continue'; it runs one piece to completion, then picks the next ready task - which is how one thread stays concurrent, and why a long synchronous task freezes everything.
  3. Promises & async/await A promise is a value that isn't here yet; await means 'pause this function until the value is ready, without freezing the event loop.' async/await is readable syntax over the exact same model - and forgetting await or ignoring a rejection are the two mistakes that bite everyone.