refactor: use Array.from to build Array() from Map()
[poolifier.git] / src / pools / selection-strategies / worker-choice-strategies-context.ts
index d088015acc1ad9b62fd57a1221871e42210418bb..185fed71287e668179e201d7ee79848463fd1d76 100644 (file)
@@ -137,11 +137,10 @@ export class WorkerChoiceStrategiesContext<
    * @returns `true` if the update is successful, `false` otherwise.
    */
   public update (workerNodeKey: number): boolean {
-    const res: boolean[] = []
-    for (const workerChoiceStrategy of this.workerChoiceStrategies.values()) {
-      res.push(workerChoiceStrategy.update(workerNodeKey))
-    }
-    return res.every(r => r)
+    return Array.from(
+      this.workerChoiceStrategies,
+      ([_, workerChoiceStrategy]) => workerChoiceStrategy.update(workerNodeKey)
+    ).every(r => r)
   }
 
   /**
@@ -195,11 +194,10 @@ export class WorkerChoiceStrategiesContext<
    * @returns `true` if the removal is successful, `false` otherwise.
    */
   public remove (workerNodeKey: number): boolean {
-    const res: boolean[] = []
-    for (const workerChoiceStrategy of this.workerChoiceStrategies.values()) {
-      res.push(workerChoiceStrategy.remove(workerNodeKey))
-    }
-    return res.every(r => r)
+    return Array.from(
+      this.workerChoiceStrategies,
+      ([_, workerChoiceStrategy]) => workerChoiceStrategy.remove(workerNodeKey)
+    ).every(r => r)
   }
 
   /**