Series · 4 parts · ~66 min read
Async JavaScript: how the engine runs your async code
Four posts build the async model bottom-up: event loop, promises as a state machine, async/await, and generators — the pause/resume primitive under it all.
- 01
Event Loop in JavaScript - how the engine decides what runs next
Read NextJavaScript has one thread, but it can wait for many things at once. The trick is the event loop - a simple algorithm that picks what to run when the stack is empty. Microtasks beat tasks, render fits between cycles, and execution order starts to make sense.
18 min read Read → - 02
Promises in JavaScript - from callback hell to the microtask queue
Read NextAsync in JS without Promises is callback hell - the code has no way to refer to the in-flight operation, and error handling sits separately inside every callback. A Promise stands in for a value that will arrive later - the code reads flat, and you catch errors in one place.
25 min read Read → - 03
async/await in JavaScript - how a function can wait without blocking the thread
Read Nextasync/awaitlooks like magic: you writeawait fetch(...), get the result on the next line, and the thread doesn't block for a single moment. Underneath there's no magic - just an old pattern of generator + Promise + auto-runner, hidden under the new keywordsasyncandawait.12 min read Read → - 04
Generators in JavaScript - a function that knows how to pause
Read NextA regular JS function runs top to bottom, returns a value, and disappears from memory. A generator is different - marked with
function*, it pauses on everyyield, hands a value out, and waits for the next.next(). A small change in the runtime, but it's the one that powers on-demand sequences and lives under the hood ofasync/await.11 min read Read →