What is process.nextTick()?

The event loop is what allows Node.js to perform non-blocking I/O operations
Post Reply
aryatechno
Site Admin
Posts: 9
Joined: Tue Sep 26, 2023 9:01 am

What is process.nextTick()?

Post by aryatechno »

You may have noticed that process.nextTick() was not displayed in the diagram, even though it's a part of the asynchronous API. This is because process.nextTick() is not technically part of the event loop. Instead, the nextTickQueue will be processed after the current operation is completed, regardless of the current phase of the event loop. Here, an operation is defined as a transition from the underlying C/C++ handler, and handling the JavaScript that needs to be executed.

Looking back at our diagram, any time you call process.nextTick() in a given phase, all callbacks passed to process.nextTick() will be resolved before the event loop continues. This can create some bad situations because it allows you to "starve" your I/O by making recursive process.nextTick() calls, which prevents the event loop from reaching the poll phase.
Post Reply