worker.exitedAfterDisconnect
如果工作线程由于调用 .disconnect() 而退出,则该属性为 true。如果工作线程以其他方式退出,则该属性为 false。如果工作线程尚未退出,则该属性为 undefined。
【This property is true if the worker exited due to .disconnect().
If the worker exited any other way, it is false. If the
worker has not exited, it is undefined.】
布尔值 worker.exitedAfterDisconnect 允许区分自愿退出和意外退出,主节点可以根据该值选择是否重新生成工作线程。
【The boolean worker.exitedAfterDisconnect allows distinguishing between
voluntary and accidental exit, the primary may choose not to respawn a worker
based on this value.】
cluster.on('exit', (worker, code, signal) => {
if (worker.exitedAfterDisconnect === true) {
console.log('Oh, it was just voluntary – no need to worry');
}
});
// kill worker
worker.kill();