Async Era
ES2017+2017 – 2019`async`/`await` made the microtask queue an everyday concern. Asynchronous code finally reads top-to-bottom while still yielding to the loop at each await.
An async function returns a promise and suspends at every `await`, popping its frame off the call stack and resuming later as a microtask. Run this in the visualizer to watch the frame leave and come back.
async function fetchStep(label) {
console.log("enter", label);
await null; // suspends here, resumes as a microtask
console.log("resume", label);
return label;
}
async function main() {
const a = await fetchStep("A");
const b = await fetchStep("B");
console.log("done:", a, b);
}
main();
console.log("this line runs before any resume");