docs: add scope on pool public API
[poolifier.git] / src / pools / selection-strategies / least-used-worker-choice-strategy.ts
index 8c1384701de0c2d37b5c34a474394f8baa92141d..e8a7218e160879bcaa97399d78a3b39ff7857bc1 100644 (file)
@@ -42,6 +42,15 @@ export class LeastUsedWorkerChoiceStrategy<
 
   /** @inheritDoc */
   public choose (): number {
+    return this.leastUsedNextWorkerNodeKey()
+  }
+
+  /** @inheritDoc */
+  public remove (): boolean {
+    return true
+  }
+
+  private leastUsedNextWorkerNodeKey (): number {
     let minNumberOfTasks = Infinity
     for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) {
       const workerTaskStatistics = workerNode.usage.tasks
@@ -49,22 +58,17 @@ export class LeastUsedWorkerChoiceStrategy<
         workerTaskStatistics.executed +
         workerTaskStatistics.executing +
         workerTaskStatistics.queued
-      if (this.workerNodeReady(workerNodeKey) && workerTasks === 0) {
-        this.nextWorkerNodeId = workerNodeKey
+      if (this.isWorkerNodeReady(workerNodeKey) && workerTasks === 0) {
+        this.nextWorkerNodeKey = workerNodeKey
         break
       } else if (
-        this.workerNodeReady(workerNodeKey) &&
+        this.isWorkerNodeReady(workerNodeKey) &&
         workerTasks < minNumberOfTasks
       ) {
         minNumberOfTasks = workerTasks
-        this.nextWorkerNodeId = workerNodeKey
+        this.nextWorkerNodeKey = workerNodeKey
       }
     }
-    return this.nextWorkerNodeId
-  }
-
-  /** @inheritDoc */
-  public remove (): boolean {
-    return true
+    return this.nextWorkerNodeKey
   }
 }