Complete the code to import the Worker class from the worker_threads module.
const { [1] } = require('worker_threads');The Worker class is imported from the worker_threads module to create new worker threads.
Complete the code to create a new worker thread running the script 'worker.js'.
const worker = new Worker('[1]');
The path to the worker script should be a relative path string like './worker.js' to correctly locate the file.
Fix the error in the code to listen for messages from the worker.
worker.on('[1]', (msg) => { console.log('Message from worker:', msg); });
The event name to listen for messages from a worker is 'message'.
Fill both blanks to send a message 'Hello' to the worker and listen for its response.
worker.[1]('Hello'); worker.on('[2]', (response) => { console.log('Received:', response); });
Use postMessage to send data to the worker and listen for message events to receive data from it.
Fill all three blanks to create a worker, send it data, and handle errors.
const worker = new [1]('./task.js'); worker.[2]({ task: 'compute' }); worker.on('[3]', (err) => { console.error('Worker error:', err); });
Create a Worker instance, use postMessage to send data, and listen for error events to catch errors.