mirror of https://github.com/webpack/webpack.git
better disconnect
This commit is contained in:
parent
b7e776c528
commit
0460211742
|
|
@ -4,6 +4,15 @@
|
||||||
*/
|
*/
|
||||||
var child_process = require("child_process");
|
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) {
|
function Workers(moduleToFork, count) {
|
||||||
this.nextId = 1;
|
this.nextId = 1;
|
||||||
this.workers = [];
|
this.workers = [];
|
||||||
|
|
@ -49,7 +58,7 @@ Workers.prototype.bindWorker = function(worker, idx) {
|
||||||
callback.apply(null, result);
|
callback.apply(null, result);
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
} else {
|
} else {
|
||||||
worker.disconnect();
|
disconnectWorker(worker);
|
||||||
this.forkedWorkers.splice(idx, 1);
|
this.forkedWorkers.splice(idx, 1);
|
||||||
}
|
}
|
||||||
}.bind(this));
|
}.bind(this));
|
||||||
|
|
@ -85,9 +94,7 @@ Workers.prototype.pushJob = function(worker) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Workers.prototype.close = function() {
|
Workers.prototype.close = function() {
|
||||||
this.workers.forEach(function(worker) {
|
this.workers.forEach(disconnectWorker);
|
||||||
worker.disconnect();
|
|
||||||
});
|
|
||||||
this.workers.length = 0;
|
this.workers.length = 0;
|
||||||
this.workersJobs.length = 0;
|
this.workersJobs.length = 0;
|
||||||
this.workersRegister.length = 0;
|
this.workersRegister.length = 0;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue