better disconnect

This commit is contained in:
Tobias Koppers 2012-10-26 00:19:19 +02:00
parent b7e776c528
commit 0460211742
1 changed files with 11 additions and 4 deletions

View File

@ -4,6 +4,15 @@
*/
var child_process = require("child_process");
function disconnectWorker(worker) {
if(worker.disconnect)
worker.disconnect();
else if(worker.kill)
worker.kill();
else
worker.process.kill();
}
function Workers(moduleToFork, count) {
this.nextId = 1;
this.workers = [];
@ -49,7 +58,7 @@ Workers.prototype.bindWorker = function(worker, idx) {
callback.apply(null, result);
}.bind(this));
} else {
worker.disconnect();
disconnectWorker(worker);
this.forkedWorkers.splice(idx, 1);
}
}.bind(this));
@ -85,9 +94,7 @@ Workers.prototype.pushJob = function(worker) {
}
Workers.prototype.close = function() {
this.workers.forEach(function(worker) {
worker.disconnect();
});
this.workers.forEach(disconnectWorker);
this.workers.length = 0;
this.workersJobs.length = 0;
this.workersRegister.length = 0;