16.5 Worker Threads
Since version 10.5, Node.js has had another module besides the child_process module that deals with creating parallel execution threads in an application. The newer worker_threads module is used to swap out CPU-intensive subprocesses into a separate worker thread. The strength of the child processes of the child_process module rather lies in operations involving many input and output operations. The concept behind both modules is quite similar: Both make sure that a certain part of the application gets swapped out, and they provide methods and events for communication between the main process and the child processes or child threads. Listing 16.16 contains the implementation of the worker for realizing the example with ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access