Skip to content
uencoder

Event Loop

The event loop continuously takes events from the event queue and dispatches them to callbacks, achieving single-threaded non-blocking I/O concurrency.

Purpose

Understand the JavaScript/Node.js concurrency model and avoid blocking the main thread.

Mechanism

Loop: 1) take one event from the queue; 2) run its callback to completion; 3) after the microtask queue drains, take the next event. Node.js uses libuv; browsers add rendering phases. Async I/O is delegated to the system so it does not block the loop.

Use cases

  • Concurrency model
  • Performance optimization
  • Asynchronous I/O

Related terms

References