Bird
0
0

How can you pass multiple pieces of data to a worker thread and access them easily inside the worker?

hard📝 Application Q9 of 15
Node.js - Worker Threads
How can you pass multiple pieces of data to a worker thread and access them easily inside the worker?
APass an object with all data as properties in workerData
BPass multiple arguments separately in Worker constructor
CUse multiple workerData options for each data piece
DSend data after worker creation via parentPort only
Step-by-Step Solution
Solution:
  1. Step 1: Understand workerData structure

    workerData accepts a single value, so passing an object with multiple properties is the way to send multiple data pieces.
  2. Step 2: Confirm other options are invalid

    Worker constructor does not accept multiple arguments or multiple workerData options. Sending data after creation is possible but not initial passing.
  3. Final Answer:

    Pass an object with all data as properties in workerData -> Option A
  4. Quick Check:

    Use an object to bundle multiple data in workerData [OK]
Quick Trick: Bundle multiple data in one object for workerData [OK]
Common Mistakes:
  • Trying to pass multiple separate arguments
  • Using multiple workerData options

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes