Bird
0
0

Given this worker pool code snippet, what will be logged to the console?

medium📝 component behavior Q4 of 15
Node.js - Worker Threads
Given this worker pool code snippet, what will be logged to the console?
const { Worker } = require('worker_threads');

const worker = new Worker(`
  const { parentPort } = require('worker_threads');
  parentPort.postMessage('done');
`, { eval: true });

worker.on('message', msg => console.log(msg));
Adone
Bundefined
CError: Cannot find module 'worker_threads'
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand inline worker code with eval option

    The worker runs code that sends 'done' message to parent via postMessage.
  2. Step 2: Check event listener for 'message'

    The main thread listens for 'message' and logs the received message.
  3. Final Answer:

    done -> Option A
  4. Quick Check:

    Worker message logged = done [OK]
Quick Trick: Worker sends message, main thread logs it [OK]
Common Mistakes:
  • Expecting no output due to async nature
  • Confusing error with missing modules
  • Assuming undefined is logged

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Node.js Quizzes