Browse Source

tools: move message listener to worker objects

Moving the `message` event listener from the cluster object to each
worker object allows easier backporting of the recent jslint
changes since v5.x and older do not have v6.x's `worker` parameter
in the cluster object's `message` event.

PR-URL: https://github.com/nodejs/node/pull/6212
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
process-exit-stdio-flushing
Brian White 9 years ago
committed by James M Snell
parent
commit
58561cf6a8
  1. 30
      tools/jslint.js

30
tools/jslint.js

@ -125,20 +125,6 @@ if (cluster.isMaster) {
sendWork(worker);
});
cluster.on('message', function(worker, results) {
if (typeof results !== 'number') {
// The worker sent us results that are not all successes
if (!workerConfig.sendAll)
failures += results.length;
outFn(formatter(results) + '\r\n');
printProgress();
} else {
successes += results;
}
// Try to give the worker more work to do
sendWork(worker);
});
process.on('exit', function() {
if (showProgress) {
curPath = 'Done';
@ -149,7 +135,21 @@ if (cluster.isMaster) {
});
for (i = 0; i < numCPUs; ++i)
cluster.fork();
cluster.fork().on('message', onWorkerMessage);
function onWorkerMessage(results) {
if (typeof results !== 'number') {
// The worker sent us results that are not all successes
if (!workerConfig.sendAll)
failures += results.length;
outFn(formatter(results) + '\r\n');
printProgress();
} else {
successes += results;
}
// Try to give the worker more work to do
sendWork(this);
}
function sendWork(worker) {
if (!files || !files.length) {

Loading…
Cancel
Save