- Version: 10.5.0
- Platform: Darwin
- Subsystem:
I found in the docs for the Worker following code example is outdated
constassert=require('assert');const{
Worker, MessageChannel, MessagePort, isMainThread
}=require('worker_threads');if(isMainThread){constworker=newWorker(__filename);constsubChannel=newMessageChannel();worker.postMessage({hereIsYourPort: subChannel.port1},[subChannel.port1]);subChannel.port2.on('message',(value)=>{console.log('received:',value);});}else{require('worker_threads').once('workerMessage',(value)=>{assert(value.hereIsYourPortinstanceofMessagePort);value.hereIsYourPort.postMessage('the worker is sending this');value.hereIsYourPort.close();});}should use parentPort.on("message") replaced
I found in the docs for the Worker following code example is outdated
should use
parentPort.on("message")replaced