From: Jérôme Benoit Date: Fri, 10 May 2024 14:08:21 +0000 (+0200) Subject: refactor: use Array.from to build Array() from Map() X-Git-Tag: v4.0.6~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=63af54001cdb7be2f14d51be593a7f96c8c480b6;p=poolifier.git refactor: use Array.from to build Array() from Map() Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/selection-strategies/selection-strategies-utils.ts b/src/pools/selection-strategies/selection-strategies-utils.ts index 6e63f781..3c7f5f4d 100644 --- a/src/pools/selection-strategies/selection-strategies-utils.ts +++ b/src/pools/selection-strategies/selection-strategies-utils.ts @@ -118,10 +118,10 @@ export const toggleMedianMeasurementStatisticsRequirements = ( export const buildWorkerChoiceStrategiesPolicy = ( workerChoiceStrategies: Map ): StrategyPolicy => { - const policies: StrategyPolicy[] = [] - for (const workerChoiceStrategy of workerChoiceStrategies.values()) { - policies.push(workerChoiceStrategy.strategyPolicy) - } + const policies: StrategyPolicy[] = Array.from( + workerChoiceStrategies, + ([_, workerChoiceStrategy]) => workerChoiceStrategy.strategyPolicy + ) return { dynamicWorkerUsage: policies.some(p => p.dynamicWorkerUsage), dynamicWorkerReady: policies.some(p => p.dynamicWorkerReady) @@ -131,12 +131,11 @@ export const buildWorkerChoiceStrategiesPolicy = ( export const buildWorkerChoiceStrategiesTaskStatisticsRequirements = ( workerChoiceStrategies: Map ): TaskStatisticsRequirements => { - const taskStatisticsRequirements: TaskStatisticsRequirements[] = [] - for (const workerChoiceStrategy of workerChoiceStrategies.values()) { - taskStatisticsRequirements.push( + const taskStatisticsRequirements: TaskStatisticsRequirements[] = Array.from( + workerChoiceStrategies, + ([_, workerChoiceStrategy]) => workerChoiceStrategy.taskStatisticsRequirements - ) - } + ) return { runTime: { aggregate: taskStatisticsRequirements.some(r => r.runTime.aggregate), diff --git a/src/pools/selection-strategies/worker-choice-strategies-context.ts b/src/pools/selection-strategies/worker-choice-strategies-context.ts index d088015a..185fed71 100644 --- a/src/pools/selection-strategies/worker-choice-strategies-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategies-context.ts @@ -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) } /**