← Back to miito.dev

Digital Garden

October 21
Garden HubAutomotiveTypeScriptTestingSVGSQLSecurityReactPerformanceNode.jsModdingJavaScriptGame DevDevOpsDesignCSSCommunication
miito.dev
© Brian Dinh (miito.dev)
✕
✕
§ GARDEN · NODEJS · CLASS OPEN
NODE FILE · ENTRY

The Event Loop Visualized

FILED UNDER · NODEJS
①Read
②Meta

Timers, microtasks, I/O callbacks, and the phases of Node's event loop — what actually happens between ticks.

The event loop is the heart of Node.js, but most explanations either oversimplify it ('just a queue') or drown you in libuv internals. The truth is in between: it's a series of phases, each with its own queue, processed in a specific order. Understanding this order explains why setTimeout(fn, 0) doesn't always fire before setImmediate(fn).

The Six Phases

Timers (setTimeout/setInterval), pending callbacks (deferred I/O errors), idle/prepare (internal), poll (retrieve new I/O events), check (setImmediate), close callbacks (socket.on('close')). Microtasks (Promise.then, process.nextTick) run between every phase transition, which is why they can starve the event loop if used carelessly.

DTNRWORKSHOP ARMAMENTSSN 2012.OTT.0176