GeezerVison is showing github.com — cluster: return worker reference from disconnect() · nodejs/node@ae587f3
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: doc/api/cluster.md +2Lines changed: 2 additions & 0 deletions - Display the source diff
- Display the rich diff
| Original file line number | Diff line number | Diff line change |
|---|
@@ -262,6 +262,8 @@ It is not emitted in the worker. | 262 | 262 | added: v0.7.7 | 263 | 263 | --> | 264 | 264 |
| | 265 | +* Returns: {Worker} A reference to `worker`. | | 266 | + | 265 | 267 | In a worker, this function will close all servers, wait for the `'close'` event on | 266 | 268 | those servers, and then disconnect the IPC channel. | 267 | 269 |
| |
Collapse file Copy file name to clipboardExpand all lines: lib/cluster.js +2Lines changed: 2 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -429,6 +429,7 @@ function masterInit() { | 429 | 429 | send(this, { act: 'disconnect' }); | 430 | 430 | removeHandlesForWorker(this); | 431 | 431 | removeWorker(this); | | 432 | + return this; | 432 | 433 | }; | 433 | 434 |
| 434 | 435 | Worker.prototype.destroy = function(signo) { | @@ -686,6 +687,7 @@ function workerInit() { | 686 | 687 |
| 687 | 688 | Worker.prototype.disconnect = function() { | 688 | 689 | _disconnect.call(this); | | 690 | + return this; | 689 | 691 | }; | 690 | 692 |
| 691 | 693 | Worker.prototype.destroy = function() { | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-cluster-worker-destroy.js +3-1Lines changed: 3 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 8 | 8 | */ | 9 | 9 |
| 10 | 10 | const common = require('../common'); | | 11 | +const assert = require('assert'); | 11 | 12 | const cluster = require('cluster'); | 12 | 13 | let worker1, worker2; | 13 | 14 |
| @@ -26,7 +27,8 @@ if (cluster.isMaster) { | 26 | 27 | cluster.worker.destroy(); | 27 | 28 | }); | 28 | 29 |
| 29 | | - cluster.worker.disconnect(); | | 30 | + const w = cluster.worker.disconnect(); | | 31 | + assert.strictEqual(w, cluster.worker, 'did not return a reference'); | 30 | 32 | } else { | 31 | 33 | // Call destroy when worker is not disconnected yet | 32 | 34 | cluster.worker.destroy(); | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-cluster-worker-disconnect.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -40,7 +40,8 @@ if (cluster.isWorker) { | 40 | 40 |
| 41 | 41 | // Disconnect worker when it is ready | 42 | 42 | worker.once('listening', common.mustCall(() => { | 43 | | - worker.disconnect(); | | 43 | + const w = worker.disconnect(); | | 44 | + assert.strictEqual(worker, w, 'did not return a reference'); | 44 | 45 | })); | 45 | 46 |
| 46 | 47 | // Check cluster events | |
Collapse file Copy file name to clipboardExpand all lines: test/parallel/test-cluster-worker-init.js +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -13,7 +13,8 @@ if (cluster.isMaster) { | 13 | 13 |
| 14 | 14 | worker.on('message', common.mustCall((message) => { | 15 | 15 | assert.strictEqual(message, true, 'did not receive expected message'); | 16 | | - worker.disconnect(); | | 16 | + const w = worker.disconnect(); | | 17 | + assert.strictEqual(worker, w, 'did not return a reference'); | 17 | 18 | })); | 18 | 19 |
| 19 | 20 | worker.on('online', () => { | |
|