AsyncFlow

See exactly why your async JavaScript runs in that order.

Your code

0 / 0

Call stack

empty

Microtask queue

empty

Macrotask queue

empty

Console output

call stack (LIFO) microtasks — drain fully macrotasks — one per turn

How it works

AsyncFlow parses your code with acorn (vendored, MIT) and runs it through a small purpose-built interpreter that models the JavaScript event loop. It records an immutable, step-by-step trace of everything the loop does — call-stack pushes and pops, microtask and macrotask enqueue/run, and every console.log. The player then scrubs through that trace, so stepping backward is just replaying a recorded step, never guessing.

Accuracy — what is modelled

Correctness is the whole point; a visualizer that lies is worse than none. The ordering semantics follow Jake Archibald's Tasks, microtasks, queues and schedules. Specifically:

  • The current job runs synchronously to completion first.
  • Then the entire microtask queue drains — including microtasks that other microtasks enqueue — before any macrotask runs.
  • Then exactly one macrotask (a setTimeout callback) runs, after which microtasks drain again. Repeat.
  • await x always yields to the microtask queue — even when x is already resolved (modern one-tick await, matching current V8).
  • .then callbacks are enqueued as microtasks, never run inline; returning a promise from .then costs the extra adoption tick.
  • Timers with equal delay fire in FIFO registration order.

These behaviours are pinned by a test suite that asserts exact output ordering, verified against Node.js / V8.

Simplifications & limitations

  • Supported subset: functions (declarations, expressions, arrows), calls, console.log, literals and template literals, variables, arithmetic/comparison/logical/unary operators, arrays and indexing, if/else, return, throw, new Promise, .then/.catch/.finally, Promise.resolve/reject/all/race/allSettled, async/await, setTimeout, queueMicrotask.
  • Not modelled yet: loops, try/catch, object literals, classes, destructuring, generators, real timer delays (delays only decide ordering, not wall-clock), and I/O. Using one shows a friendly "not supported yet" message with the line — never a crash and never silently-wrong output.
  • setInterval is modelled as a single one-shot fire.