Node.js - Worker Threads
You want to create a worker thread that performs a CPU-heavy calculation and sends the result back. Which approach correctly creates the worker and handles the result asynchronously?
new Worker('./calc.js') and using worker.on('message') plus worker.postMessage() is the standard pattern.new Worker() without arguments and call worker.send() to communicate is invalid because Worker requires a filename or code. Use require('worker_threads').run() to start the worker and get a promise is incorrect; no run() method exists. Create a child process with child_process.fork() and communicate with worker.postMessage() uses child_process, not worker_threads, and postMessage is not valid on child processes.15+ quiz questions · All difficulty levels · Free
Free Signup - Practice All Questions