From: Jérôme Benoit Date: Sun, 7 May 2023 20:57:11 +0000 (+0200) Subject: refactor: worker choice strategies remove() simplification X-Git-Tag: v2.4.13~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=97f4fd90399b9e17f30d6b64308599c6c4b72008;hp=b0d6ed8f66e9636805462c83e4c9290dccebb690;p=poolifier.git refactor: worker choice strategies remove() simplification Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 5e35636a..e99383ca 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -61,11 +61,8 @@ export class RoundRobinWorkerChoiceStrategy< if (this.nextWorkerNodeId === workerNodeKey) { if (this.pool.workerNodes.length === 0) { this.nextWorkerNodeId = 0 - } else { - this.nextWorkerNodeId = - this.nextWorkerNodeId > this.pool.workerNodes.length - 1 - ? this.pool.workerNodes.length - 1 - : this.nextWorkerNodeId + } else if (this.nextWorkerNodeId > this.pool.workerNodes.length - 1) { + this.nextWorkerNodeId = this.pool.workerNodes.length - 1 } } return true diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 18173949..5d8bbe2f 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -91,11 +91,8 @@ export class WeightedRoundRobinWorkerChoiceStrategy< if (this.currentWorkerNodeId === workerNodeKey) { if (this.pool.workerNodes.length === 0) { this.currentWorkerNodeId = 0 - } else { - this.currentWorkerNodeId = - this.currentWorkerNodeId > this.pool.workerNodes.length - 1 - ? this.pool.workerNodes.length - 1 - : this.currentWorkerNodeId + } else if (this.currentWorkerNodeId > this.pool.workerNodes.length - 1) { + this.currentWorkerNodeId = this.pool.workerNodes.length - 1 } this.workerVirtualTaskRunTime = 0 }