refactor: cleanup worker choice strategies code
[poolifier.git] / src / pools / selection-strategies / fair-share-worker-choice-strategy.ts
index 00c56dad8f555f64afc0a4d21a693d6a97b956f5..bf30a4764d4ffdd5287fcbbad588baddca42b193 100644 (file)
@@ -70,8 +70,7 @@ export class FairShareWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number {
-    this.fairShareNextWorkerNodeKey()
-    return this.nextWorkerNodeKey
+    return this.fairShareNextWorkerNodeKey()
   }
 
   /** @inheritDoc */
@@ -80,7 +79,7 @@ export class FairShareWorkerChoiceStrategy<
     return true
   }
 
-  private fairShareNextWorkerNodeKey (): void {
+  private fairShareNextWorkerNodeKey (): number {
     let minWorkerVirtualTaskEndTimestamp = Infinity
     for (const [workerNodeKey] of this.pool.workerNodes.entries()) {
       if (this.workersVirtualTaskEndTimestamp[workerNodeKey] == null) {
@@ -96,6 +95,7 @@ export class FairShareWorkerChoiceStrategy<
         this.nextWorkerNodeKey = workerNodeKey
       }
     }
+    return this.nextWorkerNodeKey
   }
 
   /**