Bird
0
0

In Node.js, which event handler correctly captures messages sent from a worker thread named worker?

easy📝 Syntax Q3 of 15
Node.js - Worker Threads
In Node.js, which event handler correctly captures messages sent from a worker thread named worker?
Aworker.handle('message', (msg) => { console.log(msg); });
Bworker.receive('message', (msg) => { console.log(msg); });
Cworker.listen('data', (msg) => { console.log(msg); });
Dworker.on('message', (msg) => { console.log(msg); });
Step-by-Step Solution
Solution:
  1. Step 1: Identify the correct event name

    The event to listen for messages from a worker thread is 'message'.
  2. Step 2: Use the correct method

    The method to attach an event listener is on.
  3. Final Answer:

    worker.on('message', (msg) => { console.log(msg); }); corresponds to worker.on('message', (msg) => { console.log(msg); });.
  4. Quick Check:

    Check event name and method usage [OK]
Quick Trick: Use 'on' with 'message' event to receive worker messages [OK]
Common Mistakes:
  • Using incorrect event names like 'data' or 'receive'
  • Using non-existent methods like 'listen' or 'handle'
  • Confusing 'message' event with other events

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes