You add a few console.log calls to an async function to find out when a value arrives, and the output comes back in an order the code does not seem to allow. The last line of the script prints before the line after the await, a setTimeout with a delay of zero prints after everything else, and a .then on an unrelated promise runs in the middle of your function.

Async/await reads like blocking code, so most of us carry a mental model where await waits and everything else waits with it. The real mechanism is one thread, a call stack, and two queues that the runtime drains in a fixed order. Once you can see which queue each line goes through, that output stops being surprising, and so do timers that fire late and pages that freeze with no slow function in sight.

To see it, I wrote a 35-line tracer that labels every log line with the task and the microtask tick it ran on, and five small scripts that use it: pmckeetx/async-await-ticks. I wanted to know which tick each line of an async function runs on, and what each form of await and return costs, measured on Node 24.20 in November 2026. await 42 costs exactly one tick, the same as awaiting a real promise. return await promise hands the value to the caller one tick sooner than return promise. And a chain of microtasks held a 0 ms timer back for 100 ms.

A terminal running examples/costs.js. Each line is labeled with task 0 and a tick number: await 42, await promise and return value resume at tick 1, await thenable and return await promise at tick 2, and return promise at tick 3.

Two queues and a loop

To understand the output, we have to look at the two queues, the call stack they feed, and the loop that moves work between them.

The call stack holds the functions that are running right now. JavaScript runs one function at a time on a given thread, and nothing else can start until the stack is empty again. This is the run-to-completion rule, and every other piece of the model follows from it.

A task is a unit of work the host (the browser or Node) schedules from outside your code: running a script, calling a timer callback, dispatching a click, delivering a message from a worker. Tasks wait in the task queue. You will also see it called the message queue (MDN's older pages use that name), the event queue, the callback queue or the macrotask queue; they are the same thing. Strictly, the HTML standard gives an event loop several task queues and lets the browser choose which one to take from next, but within one source, such as timers, tasks run in the order they were queued.

A microtask is a smaller job queued by your own code while a task runs: a promise reaction (the callback you pass to .then), a callback passed to queueMicrotask, and, as we will see, the rest of an async function after an await. Microtasks wait in the microtask queue. The ECMAScript specification calls promise reactions jobs and leaves it to the host to schedule them, and both browsers and Node put them in the microtask queue. The HTML standard is explicit that "the microtask queue is not a task queue": it has different rules.

The event loop processing model ties them together. The loop takes one task, runs it until the call stack is empty, and then performs a microtask checkpoint: "While the event loop's microtask queue is not empty", it takes the oldest microtask and runs it. A microtask that queues another microtask extends the checkpoint, so the queue drains completely before the loop looks at the next task.

The event loop as a diagram. A call stack in the middle holding log('script: end') above script. On the left, a coral task queue holding a timer callback, a click handler and a message from a worker. On the right, a blue microtask queue holding the rest of loadUser after await and a plain then callback. Arrows show the loop: take one task and run it to completion, drain every microtask, then take the next task.

In this guide, a tick means one trip through the microtask queue: a callback queued during tick 0 runs at tick 1, and a callback it queues runs at tick 2. This has nothing to do with Node's process.nextTick, which comes up near the end.

Set up the project

To follow along, you will need Node 24 or later; the scripts have no dependencies. Clone the repository and run its tests:

git clone https://github.com/pmckeetx/async-await-ticks.git cd async-await-ticks npm test 
✔ order.js: sync code, then microtasks, then the timer (131.1675ms) ✔ desugared.js prints the same trace as order.js (289.056292ms) ✔ costs.js: ticks per await and return form (146.779042ms) ✔ interleave.js: two loops take turns, the sleeper waits for a task (143.213041ms) ✔ starve.js: a microtask chain holds the timer back, yielding lets it through (368.985291ms) ℹ tests 5 ... ℹ pass 5 ℹ fail 0 

Each test runs one of the example scripts in a child process and checks its output line by line, so a passing run means your Node prints the same traces this post shows. Every command from here on runs from the repository root.

Step 1: Label every log line with its tick

The runtime does not expose its queues, so we cannot print their contents directly. What we can do is keep a counter that moves forward by one each tick, and stamp its value on every log line.

Here is the first half of trace.js, which holds the counter:

// Label every log line with the task and the microtask tick it ran on. // // A tick is one trip through the microtask queue. The counter queues a // microtask at the start of each task; when it runs it bumps the tick and // queues itself again. Anything queued during tick N runs after the counter's // tick N + 1 is queued, so it sees tick N + 1. It stops after MAX_TICKS: // a counter that re-queued itself forever would never let the next task run. const MAX_TICKS = 8; let task = 0; let tick = 0; function count(n = 1) { tick = n; if (n < MAX_TICKS) queueMicrotask(() => count(n + 1)); } 

The idea rests on the microtask queue being first in, first out. At the start of each task, the counter queues itself. When it runs, it sets tick to n and queues its next run at the back of the queue. Anything your code queued during tick 0 sits in line behind the counter's first run, so it runs while tick reads 1. Anything queued during tick 1 sits behind the counter's second run, and so on. This only works if the counter is first in line, which is why every example imports trace.js before it queues anything.

MAX_TICKS stops the counter after eight ticks. Without that limit, the counter would re-queue itself forever, the microtask checkpoint would never end, and no timer would ever fire. Step 6 does this on purpose to show what it costs.

The second half exports the three functions the examples use:

export function startTask() { tick = 0; queueMicrotask(() => count()); } export function later(fn, ms = 0) { setTimeout(() => { task += 1; startTask(); fn(); }, ms); } export function log(message) { console.log(`task ${task} tick ${tick} ${message}`); } startTask(); 

startTask() resets the tick and starts the counter for a new task. It runs once when the module loads, which makes the script itself task 0. In Node, an ES module is evaluated inside the microtask queue, not as a task of its own, but nothing in these examples can tell the difference. later() is setTimeout with one addition: when the timer fires, it bumps the task number and starts a fresh counter before calling your callback, so lines inside a timer read task 1, task 2 and so on. log() stamps both numbers on the message.

The tracer queues microtasks of its own, so remove it before you ship. It does not change the order of your callbacks relative to each other, which is what the tests check.

Step 2: Trace an async function

With the tracer in place, we can run the script from the opening and read the labels. Here is examples/order.js:

import { log, later } from '../trace.js'; async function loadUser() { log('loadUser: start'); const user = await 'ada'; log(`loadUser: got ${user}`); return user; } log('script: start'); later(() => log('timer: fired')); loadUser().then((user) => log(`script: then(${user})`)); Promise.resolve().then(() => log('script: plain then')); log('script: end'); 

The script defines an async function that awaits a string, schedules a 0 ms timer with later(), calls the async function and attaches a .then to the promise it returns, queues a plain .then on an already resolved promise, and logs its own end. Run it:

node examples/order.js 
task 0 tick 0 script: start task 0 tick 0 loadUser: start task 0 tick 0 script: end task 0 tick 1 loadUser: got ada task 0 tick 1 script: plain then task 0 tick 2 script: then(ada) task 1 tick 0 timer: fired 

Notice where loadUser: start lands. Calling an async function runs its body synchronously, on the caller's stack, up to the first await. Nothing about the async keyword defers the start.

At the await, the function is suspended and the call returns a pending promise to the script. The script carries on: it queues the plain .then and logs script: end. await pauses only the async function it sits in, and the caller keeps running.

The rest of loadUser was queued as a microtask when the await ran, before the plain .then was queued, so at tick 1 it runs first and logs got ada. Its return user resolves the promise the script holds, which queues the script's .then callback for tick 2. Only when the microtask queue is empty does the loop take the next task, the timer, which starts again at tick 0 of task 1.

Four snapshots of order.js on Node 24.20, each showing what is running, the microtask queue, the waiting tasks and what was printed. At the end of the script, the microtask queue holds the rest of loadUser and the plain then, and the timer is waiting. At tick 1 both microtasks run and the script's then is queued. At tick 2 it runs and the microtask queue is empty. Then the timer callback runs as task 1.

Step 3: Rewrite await as .then

The trace suggests that await is a .then attached to the rest of the function. We can test that claim by writing the same function without async or await and checking whether it prints the same trace.

Here is the rewritten loadUser in examples/desugared.js; the script below it is the same as in order.js:

import { log, later } from '../trace.js'; // loadUser from order.js with the await written out by hand. function loadUser() { return new Promise((resolve, reject) => { log('loadUser: start'); Promise.resolve('ada').then((user) => { log(`loadUser: got ${user}`); resolve(user); }, reject); }); } 

The function returns a new promise, which plays the part of the promise an async function returns. Its synchronous part runs inside the executor, just as the body of an async function runs up to its first await. Promise.resolve('ada') wraps the awaited value in a promise, and the callback passed to .then holds everything that came after the await. The return user of the original becomes resolve(user), and if the awaited promise rejects, the rejection goes to reject. The sketch leaves one case out: an error thrown after the await would also need a try and catch around the callback body to reach reject, which an async function does for you.

Compare the two traces with diff. The <( ) syntax is process substitution, which runs each command and hands its output to diff as if it were a file; it works in bash and zsh, but not in plain sh:

diff <(node examples/order.js) <(node examples/desugared.js) && echo identical 
identical 

This is the ECMAScript definition of Await, almost step for step. It calls PromiseResolve on the value, which returns a native promise unchanged and otherwise creates a new promise resolved with the value. It then calls PerformPromiseThen to attach the rest of the function as the reaction, suspends the function, and resumes the caller. A promise reaction always runs as a job, which browsers and Node run as microtasks, so await costs at least one tick even when the value is not a promise at all.

Step 4: Count what each await and return costs

Knowing that await is a .then, we can predict how many ticks each form takes and then measure it. Here is examples/costs.js:

import { log } from '../trace.js'; const done = Promise.resolve('done'); const thenable = { then(resolve) { resolve('done'); } }; async function awaitValue() { await 42; log('await 42: resumed'); } async function awaitPromise() { await done; log('await promise: resumed'); } async function awaitThenable() { await thenable; log('await thenable: resumed'); } async function returnValue() { return 'done'; } async function returnAwait() { return await done; } async function returnPromise() { return done; } awaitValue(); awaitPromise(); awaitThenable(); returnValue().then(() => log('return value: caller resumed')); returnAwait().then(() => log('return await promise: caller resumed')); returnPromise().then(() => log('return promise: caller resumed')); 

The first three functions each await something different and log when they resume. A thenable is an object with a then method that is not a native promise, such as a promise from an old library. The last three functions return something different, and the script logs when the caller's .then runs, since that is the moment the returned value reaches the code that is waiting for it.

Run it with node examples/costs.js; the output is the terminal at the top of this post. These are the results on Node 24.20.0, on macOS, on 17 November 2026, in the order the script prints them; Chrome 157 printed the same ticks:

Printed label Form Tick
await 42 await 42 1
await promise await done (a resolved native promise) 1
return value return 'done' 1
await thenable await thenable 2
return await promise return await done 2
return promise return done 3

Awaiting a plain value and awaiting a native promise cost the same single tick, because PromiseResolve hands a native promise back unchanged and the reaction is attached to it directly. A thenable costs one more, because PromiseResolve cannot trust it: it creates a fresh, pending promise and resolves it with the thenable, and resolving with a thenable queues a NewPromiseResolveThenableJob that calls the thenable's then on a later tick. A subclass of Promise takes the same slow path.

The same job explains the return rows. When an async function returns a plain value, its promise resolves at once and the caller's .then runs one tick later. When it returns a promise, the promise it returns is resolved with that promise, which is a thenable, so the runtime spends one tick on the thenable job, one tick on the inner promise's reaction, and only then resolves the outer promise for the caller's .then. With return await promise, the await resumes the function at tick 1 with a plain value, and the caller's .then follows at tick 2.

These numbers are recent. Until V8 7.2 and Chrome 72, which shipped in January 2019, awaiting a native promise took at least three ticks; V8 cut it to one, and TC39 merged the same change into the specification in February 2019 (PR #1250). Node picked it up in Node 12.

Watch out: return await is no longer the slow option Dropping the await from return await saved ticks before 2019, and ESLint deprecated its no-return-await rule in v8.46.0. Today return await promise is a tick faster, and inside a try block it is the only return form whose rejection the catch can see.

Step 5: Interleave two async loops

The same mechanics decide what happens when two async functions run at once. Here is examples/interleave.js:

import { log, later } from '../trace.js'; async function worker(name) { for (let i = 1; i <= 3; i++) { await null; log(`${name}: i=${i}`); } } async function sleeper() { await new Promise((resolve) => later(resolve)); log('sleeper: woke up'); } sleeper(); worker('a'); worker('b'); log('script: end'); 

Each worker loops three times and awaits null on every iteration, so each iteration costs one tick. The sleeper awaits a promise that only a timer resolves. The script starts the sleeper first, then two workers, then logs its end. Run it:

node examples/interleave.js 
task 0 tick 0 script: end task 0 tick 1 a: i=1 task 0 tick 1 b: i=1 task 0 tick 2 a: i=2 task 0 tick 2 b: i=2 task 0 tick 3 a: i=3 task 0 tick 3 b: i=3 task 1 tick 1 sleeper: woke up 

The two workers take turns. Each await null puts the rest of that iteration at the back of the microtask queue, behind the other worker's iteration, so a and b alternate one tick at a time. No two lines ever run at the same moment; the functions are concurrent, but they share one thread and hand it over only at an await.

The sleeper started first and still finished last. Its promise cannot resolve until the timer task runs, and the timer task cannot run until the workers' microtasks are gone. The timer callback resolves the promise at tick 0 of task 1, and the rest of sleeper runs one tick later.

The same ordering explains a common performance bug. If the workers looped ten thousand times instead of three, every iteration would still be a microtask, the checkpoint would not end until all of them had run, and the timer would wait for the lot.

Step 6: Starve a timer with microtasks

Now let us make that consequence measurable. The script in examples/starve.js schedules a 0 ms timer, does 100 ms of work in 5 ms chunks, and records how long the timer actually waited. Here are its helpers, lines 1 to 17 of the file:

// How long does a 0 ms timer wait behind 100 ms of work? const WORK_MS = 100; const CHUNK_MS = 5; function busy(ms) { const end = performance.now() + ms; while (performance.now() < end); } function timerDelay(runWork) { return new Promise((resolve) => { const start = performance.now(); setTimeout(() => resolve(performance.now() - start), 0); runWork(); }); } 

busy() spins on performance.now() to stand in for real work, such as parsing a large response. timerDelay() records the start time, schedules the 0 ms timer, and starts the work; it resolves with the number of milliseconds the timer callback had to wait.

The rest of the same file holds the two ways of scheduling the chunks and runs both:

// Every chunk queues the next one as a microtask: the timer waits for all of them. function microtaskChain(left = WORK_MS) { busy(CHUNK_MS); if (left > CHUNK_MS) queueMicrotask(() => microtaskChain(left - CHUNK_MS)); } // Every chunk awaits a 0 ms timer: the waiting timer gets a turn between chunks. async function yieldingLoop() { for (let left = WORK_MS; left > 0; left -= CHUNK_MS) { busy(CHUNK_MS); await new Promise((resolve) => setTimeout(resolve, 0)); } } const chained = await timerDelay(microtaskChain); console.log(`microtask chain: the 0 ms timer fired after ${chained.toFixed(1)} ms`); const yielding = await timerDelay(yieldingLoop); console.log(`yielding loop: the 0 ms timer fired after ${yielding.toFixed(1)} ms`); 

microtaskChain() runs a chunk and queues the next chunk with queueMicrotask. yieldingLoop() runs a chunk and then awaits a promise that a 0 ms timer resolves, which is the same await as before but on something that has to go through the task queue. Run it:

node examples/starve.js 
microtask chain: the 0 ms timer fired after 100.1 ms yielding loop: the 0 ms timer fired after 5.1 ms 

Across three runs on Node 24.20 on 17 November 2026, the microtask chain held the timer back for 100.1 to 100.3 ms, which is all twenty chunks. Every chunk queued its successor before the checkpoint could end, so the loop never reached the task queue. The yielding loop let the timer through after 5.1 to 5.2 ms, which is one chunk: the first chunk runs synchronously, the loop then waits on a timer of its own, and the waiting timer, queued earlier, goes first. In a Chrome 157 tab the same script printed 111.3 ms and 5.2 ms.

In a browser, the stakes are higher than a late timer. The HTML standard (as of November 2026) queues rendering as its own task, "on the rendering task source", when the display is ready for a new frame. A long microtask chain therefore blocks painting and input handling as well, and the page freezes even though no single function runs for long. Yielding through the task queue is the fix in both runtimes. In browsers, nested timers are clamped to at least 4 ms once the nesting level passes 5, so each yield there costs a little more than it does in Node, where setImmediate is another way to yield.

Node and the browser

The order of every trace in this post is the same in Node and in Chrome: I ran the five scripts in both, and the four ordering scripts printed identical traces. Timing differs, as the Chrome numbers above show, and a few rules differ in ways that change the order you see.

Node keeps a third queue for process.nextTick callbacks. In a CommonJS script, Node drains the next-tick queue before the promise microtask queue. In an ES module, the order flips, because the module itself is evaluated inside the microtask queue, so promise callbacks queued there run before next-tick callbacks. The examples in the repository avoid process.nextTick for that reason, and use queueMicrotask, which behaves the same everywhere.

Note: Mixing nextTick and promises? The Node documentation covers the CommonJS and ES module ordering in when to use queueMicrotask() vs. process.nextTick(). If you need a callback to run after the current operation, queueMicrotask gives the same order in both module systems.

Since Node 11, Node also drains the microtask queue between individual timer callbacks, as browsers do. If two timers fire in the same turn and the first one queues a promise reaction, that reaction runs before the second timer. Node 10 and earlier ran every due timer first, so the same script can print a different order there.

Troubleshooting

Symptom Likely cause Fix
A setTimeout(fn, 0) callback runs tens of milliseconds late A microtask chain, or an async loop that only awaits resolved values, is running in the same task Yield through the task queue between chunks: await new Promise((resolve) => setTimeout(resolve, 0)), or setImmediate in Node
The page freezes, but no single function is slow Same cause: the microtask checkpoint never ends, so rendering tasks never run Same fix, in chunks of a few milliseconds
await inside array.forEach does not wait forEach ignores the promise each async callback returns, so the code after it runs first Use for...of with await, or await Promise.all(array.map(...))
A rejected promise escapes the try around return promise return promise hands the promise to the caller without the function ever awaiting it, so the rejection happens outside the try Write return await promise inside try
Node exits with a stack trace from an async function that nobody awaited Nothing handled the rejected promise the call returned await the call or attach a .catch
The order changes between Node versions or module systems Node before 11 ran all due timers before microtasks; process.nextTick runs at a different point in CommonJS and ES modules Run the snippet with trace.js on the runtime you ship

Where to go next

You now have a model you can test: a task runs to completion, the microtask queue drains completely, await is a .then on the rest of its function, and every await and return has a cost you can count with a 35-line tracer.

From here, try running your own puzzling snippet through trace.js before reasoning about it, or read the event loop processing model in the HTML standard itself. MDN's page on await covers top-level await and the ordering rules in reference form. The code is at pmckeetx/async-await-ticks, and a star helps other developers find it.