From 2a3cca7ec566a90e065ba8513c102632b0bddc52 Mon Sep 17 00:00:00 2001 From: gengjiawen Date: Wed, 27 Feb 2019 23:12:33 +0800 Subject: [PATCH] cluster: improve for-loop MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/26336 Reviewed-By: Luigi Pinca Reviewed-By: Michaël Zasso Reviewed-By: Ruben Bridgewater Reviewed-By: Сковорода Никита Андреевич Reviewed-By: James M Snell --- lib/internal/cluster/master.js | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/lib/internal/cluster/master.js b/lib/internal/cluster/master.js index a0e194c63ef3c3..3869ebbd8a40a2 100644 --- a/lib/internal/cluster/master.js +++ b/lib/internal/cluster/master.js @@ -80,10 +80,7 @@ cluster.setupMaster = function(options) { if (message.cmd !== 'NODE_DEBUG_ENABLED') return; - var key; - for (key in cluster.workers) { - const worker = cluster.workers[key]; - + for (const worker of Object.values(cluster.workers)) { if (worker.state === 'online' || worker.state === 'listening') { process._debugProcess(worker.process.pid); } else { @@ -227,11 +224,10 @@ cluster.disconnect = function(cb) { if (workers.length === 0) { process.nextTick(() => intercom.emit('disconnect')); } else { - for (var key in workers) { - key = workers[key]; - - if (cluster.workers[key].isConnected()) - cluster.workers[key].disconnect(); + for (const worker of Object.values(cluster.workers)) { + if (worker.isConnected()) { + worker.disconnect(); + } } }