Tapas Adhikary
Educator @tapaScript | Founder CreoWis & ReactPlay - Writer - YouTuber - Open Source
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...
blog.greenroots.info2 min read
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.