Ever wondered how JavaScript knows when to run your .then() block? Or why your console.log("done") appear before a resolved promise result? Let’s break it down in this quick TidBit! What is a Promise? A Promise is JavaScript’s way of saying: “I’ll g...

Markdown supported · ⌘↵ to post
This microtask vs macrotask priority is something I ran into the hard way building an async agent orchestration system on Node.js. I had a chain of Promise.resolve() callbacks coordinating sub-processes, and a setTimeout(0) health check that kept getting starved because the microtask queue never fully drained between cycles.
Ended up refactoring the health checks to use setImmediate() on the I/O callback phase instead, which gave them a more predictable slot in the loop.
One thing I am curious about — have you noticed any practical difference in how queueMicrotask() behaves vs Promise.resolve().then() in terms of ordering? In theory they both hit the microtask queue, but I have seen some edge cases with nested microtasks where the scheduling felt slightly different.
George Blue
Really clear explanation of why promise callbacks jump ahead of setTimeout even with a zero delay. The step-by-step walkthrough of the microtask queue draining before the next macrotask finally made the ordering click for me. I'll keep this one bookmarked for the next time an async bug has me confused.