send

fun send(message: Serializable, callback: (<Error class: unknown class>?) -> Unit = definedExternally): Boolean(source)

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);
  });
}

Since

v0.7.0

Parameters

options

The options argument, if present, is an object used to parameterize the sending of certain types of handles.


fun send(message: Serializable, sendHandle: SendHandle, callback: (<Error class: unknown class>?) -> Unit = definedExternally): Boolean(source)
fun send(    message: Serializable,     sendHandle: SendHandle,     options: MessageOptions = definedExternally,     callback: (<Error class: unknown class>?) -> Unit = definedExternally): Boolean(source)