当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Node.js Worker 'exit'事件用法及代码示例


事件:'exit'

添加于:v0.11.2

参数
  • code <number> 退出代码,如果它正常退出。
  • signal <string> 导致进程被终止的信号的名称(例如 'SIGHUP' )。

类似于 cluster.on('exit') 事件,但特定于该工作人员。

import cluster from 'node:cluster';

const worker = cluster.fork();
worker.on('exit', (code, signal) => {
  if (signal) {
    console.log(`worker was killed by signal: ${signal}`);
  } else if (code !== 0) {
    console.log(`worker exited with error code: ${code}`);
  } else {
    console.log('worker success!');
  }
});const cluster = require('node:cluster');

const worker = cluster.fork();
worker.on('exit', (code, signal) => {
  if (signal) {
    console.log(`worker was killed by signal: ${signal}`);
  } else if (code !== 0) {
    console.log(`worker exited with error code: ${code}`);
  } else {
    console.log('worker success!');
  }
});

相关用法


注:本文由纯净天空筛选整理自nodejs.org大神的英文原创作品  'exit'事件。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。