From 3234a413b663b98a73bf4528d50c823dfbb2441e Mon Sep 17 00:00:00 2001 From: Brian White Date: Fri, 15 Apr 2016 01:25:21 -0400 Subject: [PATCH] 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 Reviewed-By: James M Snell Reviewed-By: Jeremiah Senkpiel --- tools/jslint.js | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/tools/jslint.js b/tools/jslint.js index 7cd2fd7bcb..754ac1a98c 100644 --- a/tools/jslint.js +++ b/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) {