Skip to content

Commit

Permalink
tools: move message listener to worker objects
Browse files Browse the repository at this point in the history
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: #6212
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
  • Loading branch information
mscdex authored and jasnell committed Apr 26, 2016
1 parent 4504182 commit 3234a41
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions tools/jslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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) {
Expand Down

0 comments on commit 3234a41

Please sign in to comment.