u/unmaintainablejsin r/node • Recommends
On “How do certain libraries bypass the single-threaded nature of NodeJS?”
…f the V8, as well as runtime optimizations (selective compilation to machine code) performed by Turbofan are both single-threaded, the Orinoco garbage collector sometimes uses helper threads in order to perform parallel scavenging, concurrent marking and sweeping.
Here are some insightful talks on these topics:
- Great overview of the event loop: link to this video
- Inner workings of the Orinoco GC in V8: link to this video
EDIT: as of the title question, the plain JS that you write will generally be executed in the main thread. If I remember correctly, there is a way to write a function that will be queued for execution in the libuv's thread pool when developing Node addons in C++ and that seems to be the cas…