Thread Pool · Level 7 of 7

Notes are copies

Main sends an object to a worker, and the worker changes it. Does main's object change?

const { Worker } = require('node:worker_threads');const w = new Worker(`  const { parentPort } = require('node:worker_threads');  parentPort.on('message', (order) => {    order.dish = 'changed';    parentPort.postMessage(order.dish);  });`, { eval: true });const order = { dish: 'soup' };w.postMessage(order);w.on('message', (dish) => {  console.log('worker has ' + dish);  console.log('main has ' + order.dish);  w.terminate();});

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…