Why an awaited value becomes a microtask
Why an awaited value becomes a microtask in JavaScript: await 1 takes one tick and awaiting a thenable takes more. Node.js 24.
await always continues in a microtask, but how many ticks that takes depends on what you await. A plain value takes one, and a thenable takes extra steps.
const order = [];
const thenable = {
then(resolve) {
order.push('then called');
resolve('t');
},
};
(async () => {
await 1;
order.push('after await 1');
})();
(async () => {
await thenable;
order.push('after await thenable');
})();
Promise.resolve()
.then(() => order.push('tick 1'))
.then(() => order.push('tick 2'))
.then(() => order.push('tick 3'));
await new Promise((resolve) => setTimeout(resolve, 0));
console.log(order.join(' > '));after await 1 > then called > tick 1 > after await thenable > tick 2 > tick 3await 1 wraps the value in a resolved promise and queues the continuation at once. A thenable is different: the engine queues a job that calls its then method, and only after then has called resolve does the continuation get queued, which takes the extra tick. The tick chain shows the position: the thenable continuation lands between tick 1 and tick 2. The rules are in the ECMAScript spec for await.
Do not write code that depends on this order. It matters when you debug an interleaving between several async functions.