Recall & Review
beginner
What is the main way to receive results from worker threads in Node.js?
You listen for the 'message' event on the worker instance to receive data sent back from the worker thread.
Click to reveal answer
beginner
How do you send data from a worker thread back to the main thread?
Use the worker's parentPort.postMessage() method inside the worker to send data back to the main thread.
Click to reveal answer
intermediate
Why is it important to handle errors when receiving results from workers?
Because workers run in separate threads, errors can happen independently. Handling errors prevents crashes and helps debug issues.
Click to reveal answer
beginner
What Node.js module do you use to create worker threads?
You use the 'worker_threads' module to create and manage worker threads.
Click to reveal answer
intermediate
How can you ensure the main thread waits for a worker's result before continuing?
You can wrap the worker's message event in a Promise and await it, so the main thread pauses until the worker sends its result.
Click to reveal answer
Which event do you listen to on a worker to get results?
✗ Incorrect
The 'message' event is emitted when the worker sends data back to the main thread.
How do you send data from the main thread to a worker?
✗ Incorrect
The main thread uses worker.postMessage() to send data to the worker.
Which module must you import to use worker threads?
✗ Incorrect
The 'worker_threads' module provides the Worker class for threading.
What method inside a worker sends messages back to the main thread?
✗ Incorrect
Inside a worker, parentPort.postMessage() sends data back to the main thread.
How can you handle worker results asynchronously in the main thread?
✗ Incorrect
Wrapping the message event in a Promise lets you await the worker's result cleanly.
Explain how the main thread receives and handles results from a worker thread in Node.js.
Think about events and message passing between threads.
You got /5 concepts.
Describe how you can make the main thread wait for a worker's result before continuing execution.
Consider how async code can pause until data arrives.
You got /4 concepts.