From 001629ef3769dff3100fdf77a9400c84544a7b94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 21 Oct 2023 18:54:49 +0200 Subject: [PATCH 1/5] cluster: replace forEach with for..of in lib/internal/cluster/ directory MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- lib/internal/cluster/child.js | 4 ++-- lib/internal/cluster/primary.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js index be5353c9288e15..8dd3792a30cd3e 100644 --- a/lib/internal/cluster/child.js +++ b/lib/internal/cluster/child.js @@ -270,14 +270,14 @@ function _disconnect(primaryInitiated) { } } - handles.forEach((handle) => { + for (const handle of handles) { waitingCount++; if (handle[owner_symbol]) handle[owner_symbol].close(checkWaitingCount); else handle.close(checkWaitingCount); - }); + }; handles.clear(); checkWaitingCount(); diff --git a/lib/internal/cluster/primary.js b/lib/internal/cluster/primary.js index 945f440cd19797..1b37c965c69a01 100644 --- a/lib/internal/cluster/primary.js +++ b/lib/internal/cluster/primary.js @@ -152,10 +152,10 @@ function removeWorker(worker) { function removeHandlesForWorker(worker) { assert(worker); - handles.forEach((handle, key) => { + for (const handle of handles) { if (handle.remove(worker)) handles.delete(key); - }); + }; } cluster.fork = function(env) { From 3deccf496fcb0b04eb653dfd7d781d61b5c5af1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 22 Oct 2023 21:09:21 +0200 Subject: [PATCH 2/5] refactor: silence linter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- lib/internal/cluster/child.js | 2 +- lib/internal/cluster/primary.js | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js index 8dd3792a30cd3e..ab8eb7a44dd5dd 100644 --- a/lib/internal/cluster/child.js +++ b/lib/internal/cluster/child.js @@ -277,7 +277,7 @@ function _disconnect(primaryInitiated) { handle[owner_symbol].close(checkWaitingCount); else handle.close(checkWaitingCount); - }; + } handles.clear(); checkWaitingCount(); diff --git a/lib/internal/cluster/primary.js b/lib/internal/cluster/primary.js index 1b37c965c69a01..a12c7998fefeaa 100644 --- a/lib/internal/cluster/primary.js +++ b/lib/internal/cluster/primary.js @@ -152,10 +152,10 @@ function removeWorker(worker) { function removeHandlesForWorker(worker) { assert(worker); - for (const handle of handles) { + for (const [key, handle] of handles.entries()) { if (handle.remove(worker)) handles.delete(key); - }; + } } cluster.fork = function(env) { From 0b1f164bdc43ee0f890672e5632482293fe3bfaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 23 Oct 2023 11:57:06 +0200 Subject: [PATCH 3/5] build: silence linter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- lib/internal/cluster/primary.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/internal/cluster/primary.js b/lib/internal/cluster/primary.js index a12c7998fefeaa..6dd18ef658f85e 100644 --- a/lib/internal/cluster/primary.js +++ b/lib/internal/cluster/primary.js @@ -152,6 +152,7 @@ function removeWorker(worker) { function removeHandlesForWorker(worker) { assert(worker); + // eslint-disable-next-line node-core/no-array-destructuring for (const [key, handle] of handles.entries()) { if (handle.remove(worker)) handles.delete(key); From 92a9ea30040f1dc8eaf0167b655dcf0904ab3f48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 23 Oct 2023 12:08:50 +0200 Subject: [PATCH 4/5] fix: handles in a SafeMap MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- lib/internal/cluster/child.js | 2 +- lib/internal/cluster/primary.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/internal/cluster/child.js b/lib/internal/cluster/child.js index ab8eb7a44dd5dd..501fd6d739ad19 100644 --- a/lib/internal/cluster/child.js +++ b/lib/internal/cluster/child.js @@ -270,7 +270,7 @@ function _disconnect(primaryInitiated) { } } - for (const handle of handles) { + for (const handle of handles.values()) { waitingCount++; if (handle[owner_symbol]) diff --git a/lib/internal/cluster/primary.js b/lib/internal/cluster/primary.js index 6dd18ef658f85e..766e7838300d3b 100644 --- a/lib/internal/cluster/primary.js +++ b/lib/internal/cluster/primary.js @@ -153,7 +153,7 @@ function removeHandlesForWorker(worker) { assert(worker); // eslint-disable-next-line node-core/no-array-destructuring - for (const [key, handle] of handles.entries()) { + for (const [key, handle] of handles) { if (handle.remove(worker)) handles.delete(key); } From 6950c593ac11c26033e81f45846e4576b3dfc77a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 11 May 2024 21:20:36 +0200 Subject: [PATCH 5/5] Update lib/internal/cluster/primary.js Co-authored-by: Antoine du Hamel --- lib/internal/cluster/primary.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/internal/cluster/primary.js b/lib/internal/cluster/primary.js index 766e7838300d3b..107ab258a47e04 100644 --- a/lib/internal/cluster/primary.js +++ b/lib/internal/cluster/primary.js @@ -152,8 +152,7 @@ function removeWorker(worker) { function removeHandlesForWorker(worker) { assert(worker); - // eslint-disable-next-line node-core/no-array-destructuring - for (const [key, handle] of handles) { + for (const { 0: key, 1: handle } of handles) { if (handle.remove(worker)) handles.delete(key); }