Skip to content

Commit 0460211

Browse files
committed
better disconnect
1 parent b7e776c commit 0460211

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

lib/Workers.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
*/
55
var child_process = require("child_process");
66

7+
function disconnectWorker(worker) {
8+
if(worker.disconnect)
9+
worker.disconnect();
10+
else if(worker.kill)
11+
worker.kill();
12+
else
13+
worker.process.kill();
14+
}
15+
716
function Workers(moduleToFork, count) {
817
this.nextId = 1;
918
this.workers = [];
@@ -49,7 +58,7 @@ Workers.prototype.bindWorker = function(worker, idx) {
4958
callback.apply(null, result);
5059
}.bind(this));
5160
} else {
52-
worker.disconnect();
61+
disconnectWorker(worker);
5362
this.forkedWorkers.splice(idx, 1);
5463
}
5564
}.bind(this));
@@ -85,9 +94,7 @@ Workers.prototype.pushJob = function(worker) {
8594
}
8695

8796
Workers.prototype.close = function() {
88-
this.workers.forEach(function(worker) {
89-
worker.disconnect();
90-
});
97+
this.workers.forEach(disconnectWorker);
9198
this.workers.length = 0;
9299
this.workersJobs.length = 0;
93100
this.workersRegister.length = 0;

0 commit comments

Comments
 (0)