refactor: cleanup pool busyness checks
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 10 Apr 2023 04:15:38 +0000 (06:15 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 10 Apr 2023 04:15:38 +0000 (06:15 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts
src/pools/cluster/dynamic.ts
src/pools/thread/dynamic.ts

index 1a1a89fbcb57043c975e561e52b9962d68f35a3a..fea4847d685c1c60433b55a321c83f30dee20abf 100644 (file)
@@ -336,11 +336,7 @@ export abstract class AbstractPool<
    */
   protected chooseWorkerNode (): [number, WorkerNode<Worker, Data>] {
     let workerNodeKey: number
-    if (
-      this.type === PoolType.DYNAMIC &&
-      !this.full &&
-      this.findFreeWorkerNodeKey() === -1
-    ) {
+    if (this.type === PoolType.DYNAMIC && !this.full && this.internalBusy()) {
       const workerCreated = this.createAndSetupWorker()
       this.registerWorkerMessageListener(workerCreated, message => {
         if (
index 9f9abb01ddaa5f3015ef4a08bd2ee046dc9312c9..89180f1f161d9351190189ff06cd7e76a40f30d5 100644 (file)
@@ -46,6 +46,6 @@ export class DynamicClusterPool<
 
   /** @inheritDoc */
   public get busy (): boolean {
-    return this.full && this.findFreeWorkerNodeKey() === -1
+    return this.full && this.internalBusy()
   }
 }
index e1565d00b7949b2af74cc97f44f2bdc30185e61c..05b61684173af58c7ed7dbbc52218c874a35fa7a 100644 (file)
@@ -47,6 +47,6 @@ export class DynamicThreadPool<
 
   /** @inheritDoc */
   public get busy (): boolean {
-    return this.full && this.findFreeWorkerNodeKey() === -1
+    return this.full && this.internalBusy()
   }
 }