worker.send(message[, sendHandle[, options]][, callback])
版本历史
| 版本 | 变更 |
|---|---|
| v4.0.0 | 现在支持 |
| v0.7.0 | 新增于: v0.7.0 |
-
message<Object> -
sendHandle<Handle> -
options<Object>options参数(如果存在)是用于参数化某些类型句柄的发送的对象。options支持以下属性:\
options<Object> Theoptionsargument, if present, is an object used to parameterize the sending of certain types of handles.optionssupports the following properties: -
callback<Function> -
返回:<boolean>
\Returns: <boolean>
向工作进程或主进程发送消息,可选择使用句柄。
\Send a message to a worker or primary, optionally with a handle.
在主进程中,这会向特定的工作进程发送消息。它与 ChildProcess.send() 相同。
\In the primary, this sends a message to a specific worker. It is identical to
ChildProcess.send().
在工作进程中,这会向主进程发送消息。它与 process.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);
});
}