Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit e428bb7

Browse files
committedMar 4, 2013
cluster: Rename destroy() to kill(signal=SIGTERM)
Fix #4133, bringing the cluster worker API more in line with the child process API.
·
1 parent 384f1be commit e428bb7

6 files changed

+25
-15
lines changed
 

‎doc/api/cluster.markdown

+15-8
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ on more than one address.
178178

179179
* `worker` {Worker object}
180180

181-
When a workers IPC channel has disconnected this event is emitted. This will happen
182-
when the worker dies, usually after calling `.destroy()`.
181+
When a workers IPC channel has disconnected this event is emitted.
182+
This will happen when the worker dies, usually after calling
183+
`.kill()`.
183184

184185
When calling `.disconnect()`, there may be a delay between the
185186
`disconnect` and `exit` events. This event can be used to detect if
@@ -323,8 +324,9 @@ See: [Child Process module](child_process.html)
323324

324325
* {Boolean}
325326

326-
This property is a boolean. It is set when a worker dies after calling `.destroy()`
327-
or immediately after calling the `.disconnect()` method. Until then it is `undefined`.
327+
This property is a boolean. It is set when a worker dies after calling
328+
`.kill()` or immediately after calling the `.disconnect()` method.
329+
Until then it is `undefined`.
328330

329331
### worker.send(message, [sendHandle])
330332

@@ -348,7 +350,10 @@ This example will echo back all messages from the master:
348350
});
349351
}
350352

351-
### worker.destroy()
353+
### worker.kill([signal='SIGTERM'])
354+
355+
* `signal` {String} Name of the kill signal to send to the worker
356+
process.
352357

353358
This function will kill the worker, and inform the master to not spawn a
354359
new worker. The boolean `suicide` lets you distinguish between voluntary
@@ -360,9 +365,11 @@ and accidental exit.
360365
}
361366
});
362367

363-
// destroy worker
364-
worker.destroy();
368+
// kill worker
369+
worker.kill();
365370

371+
This method is aliased as `worker.destroy()` for backwards
372+
compatibility.
366373

367374
### worker.disconnect()
368375

@@ -375,7 +382,7 @@ the worker finally die.
375382

376383
Because there might be long living connections, it is useful to implement a timeout.
377384
This example ask the worker to disconnect and after 2 seconds it will destroy the
378-
server. An alternative would be to execute `worker.destroy()` after 2 seconds, but
385+
server. An alternative would be to execute `worker.kill()` after 2 seconds, but
379386
that would normally not allow the worker to do any cleanup if needed.
380387

381388
if (cluster.isMaster) {

‎lib/cluster.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,10 @@ Worker.prototype.send = function() {
401401
};
402402

403403
// Kill the worker without restarting
404-
Worker.prototype.destroy = function() {
404+
Worker.prototype.kill = Worker.prototype.destroy = function(signal) {
405+
if (!signal)
406+
signal = 'SIGTERM';
407+
405408
var self = this;
406409

407410
this.suicide = true;
@@ -411,11 +414,11 @@ Worker.prototype.destroy = function() {
411414
// this way the worker won't need to propagate suicide state to master
412415
if (self.process.connected) {
413416
self.process.once('disconnect', function() {
414-
self.process.kill();
417+
self.process.kill(signal);
415418
});
416419
self.process.disconnect();
417420
} else {
418-
self.process.kill();
421+
self.process.kill(signal);
419422
}
420423

421424
} else {

‎test/simple/test-cluster-basic.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ else if (cluster.isMaster) {
102102

103103
//Kill worker when listening
104104
cluster.on('listening', function() {
105-
worker.destroy();
105+
worker.kill();
106106
});
107107

108108
//Kill process when worker is killed

‎test/simple/test-cluster-listening-port.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ if (cluster.isMaster) {
3232
assert(port);
3333
// ensure that the port is numerical
3434
assert.strictEqual(typeof(port), 'number');
35-
worker.destroy();
35+
worker.kill();
3636
});
3737
process.on('exit', function() {
3838
// ensure that the 'listening' handler has been called

‎test/simple/test-cluster-message.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ else if (cluster.isMaster) {
123123

124124
// When the connection ends kill worker and shutdown process
125125
client.on('end', function() {
126-
worker.destroy();
126+
worker.kill();
127127
});
128128

129129
worker.on('exit', function() {

‎test/simple/test-cluster-setup-master.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ if (cluster.isWorker) {
6666
if (correctIn === totalWorkers) {
6767
checks.args = true;
6868
}
69-
worker.destroy();
69+
worker.kill();
7070
});
7171

7272
// All workers are online

0 commit comments

Comments
 (0)
This repository has been archived.