It depends on how the module is implemented.
If the module is implemented without streaming support, then yes, processor binding processing cannot be performed asynchronously. Some functions provide callbacks and my view is asynchronous, but they really aren't. They actually work synchronously and block the event loop. Examples of this in javascript are Array.forEach() .
But modules can be implemented for processing in the background thread. In this case, it is really asynchronous and can speed up the tasks associated with the CPU. At the very least, it frees up an event loop to handle incoming requests, while the background thread is busy computing.
An example of this is the crypto.pbkdf2() function in node's native Crypto module.
But how can modules execute code in other threads when node.js is running on the same thread?
The initial way this was implemented was that the module was not written in javascript, but was written in C / C ++ and linked to node.js via API add-ons.
But these days, even pure javascript modules and functions can create threads and / or processes. node has an experimental module called Cluster that installs a cluster of master / slave processes node. Your module or code can then run the processor-related task in the workflow, freeing up the main node process to handle the event loop. There are several thread cutting modules at npm. Just search for "thread" at npmjs.org.
So, yes, CPU-bound tasks can run faster, or at least not block the main event loop, starting asynchronously.
source share