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>
v6.x
Brian White 9 years ago
committed by James M Snell
parent
commit
3234a413b6
  1. 28
      tools/jslint.js

28
tools/jslint.js

@ -125,7 +125,19 @@ if (cluster.isMaster) {
sendWork(worker);
});
cluster.on('message', function(worker, results) {
process.on('exit', function() {
if (showProgress) {
curPath = 'Done';
printProgress();
outFn('\r\n');
}
process.exit(failures ? 1 : 0);
});
for (i = 0; i < numCPUs; ++i)
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)
@ -136,20 +148,8 @@ if (cluster.isMaster) {
successes += results;
}
// Try to give the worker more work to do
sendWork(worker);
});
process.on('exit', function() {
if (showProgress) {
curPath = 'Done';
printProgress();
outFn('\r\n');
sendWork(this);
}
process.exit(failures ? 1 : 0);
});
for (i = 0; i < numCPUs; ++i)
cluster.fork();
function sendWork(worker) {
if (!files || !files.length) {

Loading…
Cancel
Save