Learn JavaScript

Lesson 5 of 9 · Async 1: Callbacks and the Event Loop

Module 12 · Async 1: Callbacks and the Event Loop

Under the Hood: libuv, Node's Loop Phases, nextTick, setImmediate and a Starved Loop

ProReading

Tanvir's Node server answers quickly in tests and badly under load. A colleague says "use setImmediate", another says "use process.nextTick", and a third says they are the same thing. They are not. Lessons 01 to 04 used one task queue and one microtask queue, and that picture predicts most programs. Node's real loop has more parts.

Checking what this lesson needs for you…

What is inside Under the Hood: libuv, Node's Loop Phases, nextTick, setImmediate and a Starved Loop

  1. libuv: the loop is a C library
  2. The phases of Node's loop
  3. setImmediate against setTimeout 0
  4. process.nextTick: Node's own queue, before the microtasks
  5. Microtasks run between two timers
  6. Measured: a turn of the loop against a microtask
  7. Measured: a long job starves a timer
  8. The browser's loop, and a frozen page
  9. The Playground's time limit is the judge's frozen page