worker.send()

worker.send(message[, sendHandle][, callback])

Send a message to a worker or master, optionally with a handle.

In the master this sends a message to a specific worker. It is identical to ChildProcess.send().

In a worker this sends a message to the master. It is identical to process.send().

This example will echo back all messages from the master:

1
2
3
4
5
6
7
8
9
if (cluster.isMaster) {
  var worker = cluster.fork();
  worker.send('hi there');
 
} else if (cluster.isWorker) {
  process.on('message', (msg) => {
    process.send(msg);
  });
}
doc_Nodejs
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.