![]() |
VOOZH | about |
The queueMicrotask() method in Node.js allows you to queue a function to be performed asynchronously as soon as the current code block is finished. This method only accepts one parameter, the function to be queued. The microtask is a temporary function that runs after the current task has finished its job and there is no other code waiting to be executed before control of the execution context is returned to the browser's event loop.
Syntax:
queueMicrotask(function);
Parameters: This method accepts a single parameter that is described below:
Return Value: This method returns undefined value.
Example 1: Using queueMicrotask() to execute a function after the current call stack has cleared.
Steps to run: Run the index.js file using the following command:
node index.js
Output:
Example 2: Using queueMicrotask() to create a simple task queue.
Run the index.js file using the following command:
node index.js
Output:
Reference: https://nodejs.org/api/globals.html#queuemicrotaskcallback