fork event (Cluster)

Event: 'fork'

When a new worker is forked the cluster module will emit a 'fork' event. This can be used to log worker activity, and create your own timeout.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var timeouts = [];
function errorMsg() {
  console.error('Something must be wrong with the connection ...');
}
 
cluster.on('fork', (worker) => {
  timeouts[worker.id] = setTimeout(errorMsg, 2000);
});
cluster.on('listening', (worker, address) => {
  clearTimeout(timeouts[worker.id]);
});
cluster.on('exit', (worker, code, signal) => {
  clearTimeout(timeouts[worker.id]);
  errorMsg();
});
doc_Nodejs
2025-01-10 15:47:30
Comments
Leave a Comment

Please login to continue.