| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 9ef81ff commit 47f3735
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -654,26 +654,24 @@ function workerInit() { | |||
| 654 | 654 | ||
| 655 | 655 | Worker.prototype.disconnect = function() { | |
| 656 | 656 | this.suicide = true; | |
| 657 | - var waitingHandles = 0; | ||
| 657 | + let waitingCount = 1; | ||
| 658 | 658 | ||
| 659 | - function checkRemainingHandles() { | ||
| 660 | - waitingHandles--; | ||
| 661 | - if (waitingHandles === 0) { | ||
| 659 | + function checkWaitingCount() { | ||
| 660 | + waitingCount--; | ||
| 661 | + if (waitingCount === 0) { | ||
| 662 | + send({ act: 'suicide' }); | ||
| 662 | 663 | process.disconnect(); | |
| 663 | 664 | } | |
| 664 | 665 | } | |
| 665 | 666 | ||
| 666 | - for (var key in handles) { | ||
| 667 | - var handle = handles[key]; | ||
| 667 | + for (const key in handles) { | ||
| 668 | + const handle = handles[key]; | ||
| 668 | 669 | delete handles[key]; | |
| 669 | - waitingHandles++; | ||
| 670 | - handle.owner.close(checkRemainingHandles); | ||
| 671 | - } | ||
| 672 | - | ||
| 673 | - if (waitingHandles === 0) { | ||
| 674 | - process.disconnect(); | ||
| 670 | + waitingCount++; | ||
| 671 | + handle.owner.close(checkWaitingCount); | ||
| 675 | 672 | } | |
| 676 | 673 | ||
| 674 | + checkWaitingCount(); | ||
| 677 | 675 | }; | |
| 678 | 676 | ||
| 679 | 677 | Worker.prototype.destroy = function() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,21 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + const cluster = require('cluster'); | ||
| 5 | + | ||
| 6 | + if (cluster.isMaster) { | ||
| 7 | + const worker = cluster.fork(); | ||
| 8 | + let disconnected = false; | ||
| 9 | + | ||
| 10 | + worker.on('disconnect', common.mustCall(function() { | ||
| 11 | + assert.strictEqual(worker.suicide, true); | ||
| 12 | + disconnected = true; | ||
| 13 | + })); | ||
| 14 | + | ||
| 15 | + worker.on('exit', common.mustCall(function() { | ||
| 16 | + assert.strictEqual(worker.suicide, true); | ||
| 17 | + assert.strictEqual(disconnected, true); | ||
| 18 | + })); | ||
| 19 | + } else { | ||
| 20 | + cluster.worker.disconnect(); | ||
| 21 | + } | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments