GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — cluster: return worker reference from disconnect() · nodejs/node@ae587f3

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • doc/api
    • cluster.md
  • lib
    • cluster.js
  • test/parallel
    • test-cluster-worker-destroy.js
    • test-cluster-worker-disconnect.js
    • test-cluster-worker-init.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎doc/api/cluster.md‎

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 numberDiff line numberDiff line change
@@ -262,6 +262,8 @@ It is not emitted in the worker.
262262
added: v0.7.7
263263
-->
264264

265+
* Returns: {Worker} A reference to `worker`.
266+
265267
In a worker, this function will close all servers, wait for the `'close'` event on
266268
those servers, and then disconnect the IPC channel.
267269

Collapse file

‎lib/cluster.js‎

Copy file name to clipboardExpand all lines: lib/cluster.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,7 @@ function masterInit() {
429429
send(this, { act: 'disconnect' });
430430
removeHandlesForWorker(this);
431431
removeWorker(this);
432+
return this;
432433
};
433434

434435
Worker.prototype.destroy = function(signo) {
@@ -686,6 +687,7 @@ function workerInit() {
686687

687688
Worker.prototype.disconnect = function() {
688689
_disconnect.call(this);
690+
return this;
689691
};
690692

691693
Worker.prototype.destroy = function() {
Collapse file

‎test/parallel/test-cluster-worker-destroy.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-worker-destroy.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99

1010
const common = require('../common');
11+
const assert = require('assert');
1112
const cluster = require('cluster');
1213
let worker1, worker2;
1314

@@ -26,7 +27,8 @@ if (cluster.isMaster) {
2627
cluster.worker.destroy();
2728
});
2829

29-
cluster.worker.disconnect();
30+
const w = cluster.worker.disconnect();
31+
assert.strictEqual(w, cluster.worker, 'did not return a reference');
3032
} else {
3133
// Call destroy when worker is not disconnected yet
3234
cluster.worker.destroy();
Collapse file

‎test/parallel/test-cluster-worker-disconnect.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-worker-disconnect.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ if (cluster.isWorker) {
4040

4141
// Disconnect worker when it is ready
4242
worker.once('listening', common.mustCall(() => {
43-
worker.disconnect();
43+
const w = worker.disconnect();
44+
assert.strictEqual(worker, w, 'did not return a reference');
4445
}));
4546

4647
// Check cluster events
Collapse file

‎test/parallel/test-cluster-worker-init.js‎

Copy file name to clipboardExpand all lines: test/parallel/test-cluster-worker-init.js
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ if (cluster.isMaster) {
1313

1414
worker.on('message', common.mustCall((message) => {
1515
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');
1718
}));
1819

1920
worker.on('online', () => {

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.