Keep the LRU strategy implementation as optimized as it was
authorJérôme Benoit <jerome.benoit@sap.com>
Sat, 8 Oct 2022 11:33:22 +0000 (13:33 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Sat, 8 Oct 2022 11:33:22 +0000 (13:33 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/selection-strategies/less-recently-used-worker-choice-strategy.ts

index a7892c4036e3b6e9ef742cad0bdc02eb16dbdbf3..33f6859c7776997101262edb552a88ce2a69fd72 100644 (file)
@@ -19,13 +19,12 @@ export class LessRecentlyUsedWorkerChoiceStrategy<
     // A worker is always found because it picks the one with fewer tasks
     let lessRecentlyUsedWorker!: Worker
     for (const worker of this.pool.workers) {
-      const workerRunningTasks = this.pool.getWorkerRunningTasks(worker)
-      if (!this.isDynamicPool && workerRunningTasks === 0) {
+      const workerRunningTasks = this.pool.getWorkerRunningTasks(
+        worker
+      ) as number
+      if (this.isDynamicPool === false && workerRunningTasks === 0) {
         return worker
-      } else if (
-        workerRunningTasks !== undefined &&
-        workerRunningTasks < minNumberOfRunningTasks
-      ) {
+      } else if (workerRunningTasks < minNumberOfRunningTasks) {
         lessRecentlyUsedWorker = worker
         minNumberOfRunningTasks = workerRunningTasks
       }