perf: pickup free worker in the less busy and used strategies for fixed
[poolifier.git] / src / pools / selection-strategies / less-used-worker-choice-strategy.ts
index f653160bdb29ece08cd5f1265012739da3443044..7fe56ef9dd2293ea33aaf3a9f4a2d3cda28be451 100644 (file)
@@ -20,6 +20,10 @@ export class LessUsedWorkerChoiceStrategy<
 
   /** {@inheritDoc} */
   public choose (): number {
+    const freeWorkerKey = this.pool.findFreeWorkerKey()
+    if (!this.isDynamicPool && freeWorkerKey !== false) {
+      return freeWorkerKey
+    }
     let minNumberOfTasks = Infinity
     let lessUsedWorkerKey!: number
     for (const [index, workerItem] of this.pool.workers.entries()) {