queueMicrotask()
A standard function that schedules a callback as a microtask, the same queue promise callbacks use.
In more detail
The callback runs right after the current code finishes and before any timer or rendering, the same timing as a resolved promise callback but without creating a promise. It works in browsers and Node.js alike; in Node.js it runs after any process.nextTick() callbacks already queued. Use it sparingly, because a microtask that queues another delays rendering.
Related terms
- microtask — A small job, such as a promise callback, that runs as soon as the current piece of JavaScript finishes, before the event loop handles anything else.
- Promise — A JavaScript object that stands for a result that is not ready yet and will later either succeed with a value or fail with an error.
- process.nextTick() — A Node.js function that queues a callback to run as soon as the current operation finishes, before promise callbacks and before the event loop continues.
Taught in
- The Browser Event Loop: Call Stack, Microtasks And Macrotasks — Frontend Architecture & Web Platform
- Microtask Queues: process.nextTick vs Promise Timing — Node.js Internals & Backend Services