Skip to content

OrderNot attempted

Event loop phases

Order the phases of one turn of the Node.js event loop.

Drag the rows, or use the arrows, to put them in order from first to last.

  1. Close callbacks (e.g. socket.on('close'))
  2. Check (setImmediate callbacks)
  3. Poll (retrieve new I/O; may block here waiting)
  4. Idle, prepare (internal)
  5. Pending callbacks (deferred I/O callbacks)
  6. Timers (setTimeout / setInterval callbacks)
Show answer & explanation

Correct order:

  1. Timers (setTimeout / setInterval callbacks)
  2. Pending callbacks (deferred I/O callbacks)
  3. Idle, prepare (internal)
  4. Poll (retrieve new I/O; may block here waiting)
  5. Check (setImmediate callbacks)
  6. Close callbacks (e.g. socket.on('close'))

Between EVERY callback, Node drains process.nextTick callbacks and then the promise microtask queue. The poll phase is where Node waits for I/O when there is nothing else to do.