Skip to main content

send

method Worker.prototype.send
Jump to headingWorker.prototype.send(
message: child.Serializable,
callback?: (error: Error | null) => void,
): boolean

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

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

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

This example will echo back all messages from the primary:

if (cluster.isPrimary) {
  const worker = cluster.fork();
  worker.send('hi there');

} else if (cluster.isWorker) {
  process.on('message', (msg) => {
    process.send(msg);
  });
}

Parameters Jump to heading

Jump to headingmessage: child.Serializable
optional
Jump to headingcallback: (error: Error | null) => void

Return Type Jump to heading

boolean
Jump to headingWorker.prototype.send(
message: child.Serializable,
sendHandle: child.SendHandle,
callback?: (error: Error | null) => void,
): boolean

Parameters Jump to heading

Jump to headingmessage: child.Serializable
Jump to headingsendHandle: child.SendHandle
optional
Jump to headingcallback: (error: Error | null) => void

Return Type Jump to heading

boolean
Jump to headingWorker.prototype.send(
message: child.Serializable,
sendHandle: child.SendHandle,
options?: child.MessageOptions,
callback?: (error: Error | null) => void,
): boolean

Parameters Jump to heading

Jump to headingmessage: child.Serializable
Jump to headingsendHandle: child.SendHandle
optional
Jump to headingoptions: child.MessageOptions
optional
Jump to headingcallback: (error: Error | null) => void

Return Type Jump to heading

boolean
Back to top