Bird
0
0

You want to create a worker thread that runs a function instead of a separate file. Which approach is correct?

hard📝 Conceptual Q8 of 15
Node.js - Worker Threads
You want to create a worker thread that runs a function instead of a separate file. Which approach is correct?
ACall Worker.runFunction(fn) to run a function
BPass the function directly to the Worker constructor
CUse Worker.fromFunction(fn) static method
DUse a Data URL with the function code as a string in the Worker constructor
Step-by-Step Solution
Solution:
  1. Step 1: Recall how to run code without a file

    Node.js allows creating workers from code strings using Data URLs.
  2. Step 2: Identify correct method

    You can create a Data URL with the function code and pass it to the Worker constructor.
  3. Final Answer:

    Use a Data URL with the function code as a string in the Worker constructor -> Option D
  4. Quick Check:

    Run function in worker via Data URL string [OK]
Quick Trick: Use Data URL string to run function in worker [OK]
Common Mistakes:
  • Trying to pass function directly to Worker constructor
  • Using non-existent runFunction() or fromFunction() methods
  • Assuming Worker can run functions without code string

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes