The Runtime Theory
mediumnodejs-docs#event-loop#promise-jobs

Trace an Async Function Without Guessing the Queue

Annotate which statements run now, which continuation waits, and which event settles each promise in a small Node.js program.

The Runtime Theory Team1 min read
Solve it

Solving happens on the judge — come back and mark it done

Sample cases

inLog A; await Promise.resolve(); log B; schedule setTimeout(log C, 0); log D

outPredict synchronous output, promise continuation, and timer ordering under the host's scheduling rules

inRun a long synchronous loop before a timer callback

outThe timer callback cannot run JavaScript until the current synchronous work yields

Write a short Node.js program with a synchronous log, an already-fulfilled promise, a timer, and an await. Before running it, mark each line as synchronous work, promise continuation, timer callback, or I/O completion.

Then add a CPU-heavy loop and predict which callbacks are delayed. Run the program in the same Node.js version and record the observed order; do not generalize an output ordering beyond the runtime guarantees that apply to that case.

The goal is to distinguish “the function is suspended” from “the code is running on another thread.” Use the Node.js documentation to check event-loop and worker-pool details.

One dispatch a week

The trace behind each problem, the tradeoff that explains it, and one technical dispatch per week — no noise.

One technical dispatch per week. No noise.

Not started

Sign in to save your learning progress.

Sign in to save