Skip to main content
Worker.prototype.send - node__cluster.d.ts - Node documentation
method Worker.prototype.send

Usage in Deno

```typescript import { Worker } from "node:node__cluster.d.ts"; ```
Worker.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()`](https://nodejs.org/docs/latest-v22.x/api/child_process.html#subprocesssendmessage-sendhandle-options-callback). 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: ```js if (cluster.isPrimary) { const worker = cluster.fork(); worker.send('hi there'); } else if (cluster.isWorker) { process.on('message', (msg) => { process.send(msg); }); } ```

Parameters

message: child.Serializable
optional
callback: (error: Error | null) => void

Return Type

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

Parameters

message: child.Serializable
sendHandle: child.SendHandle
optional
callback: (error: Error | null) => void

Return Type

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

Parameters

message: child.Serializable
sendHandle: child.SendHandle
optional
options: child.MessageOptions
optional
callback: (error: Error | null) => void

Return Type

boolean