fix: fix dynamic pool busy semantic
[poolifier.git] / src / pools / abstract-pool.ts
index 66b1ea1da3f3ba47d93cda9c94d2b2a19cc63ac3..1e61071c42382e1ccb9d546cb0a035ac6196afe3 100644 (file)
@@ -73,6 +73,12 @@ export abstract class AbstractPool<
     this.checkNumberOfWorkers(this.numberOfWorkers)
     this.checkFilePath(this.filePath)
     this.checkPoolOptions(this.opts)
+
+    this.chooseWorker.bind(this)
+    this.internalExecute.bind(this)
+    this.checkAndEmitBusy.bind(this)
+    this.sendToWorker.bind(this)
+
     this.setupHook()
 
     for (let i = 1; i <= this.numberOfWorkers; i++) {
@@ -137,8 +143,10 @@ export abstract class AbstractPool<
   /** {@inheritDoc} */
   public abstract get type (): PoolType
 
-  /** {@inheritDoc} */
-  public get numberOfRunningTasks (): number {
+  /**
+   * Number of tasks concurrently running.
+   */
+  private get numberOfRunningTasks (): number {
     return this.promiseResponseMap.size
   }
 
@@ -171,10 +179,13 @@ export abstract class AbstractPool<
     )
   }
 
+  /** {@inheritDoc} */
+  public abstract get full (): boolean
+
   /** {@inheritDoc} */
   public abstract get busy (): boolean
 
-  protected internalGetBusyStatus (): boolean {
+  protected internalBusy (): boolean {
     return (
       this.numberOfRunningTasks >= this.numberOfWorkers &&
       this.findFreeWorkerKey() === -1
@@ -261,7 +272,10 @@ export abstract class AbstractPool<
     }
     if (this.workerChoiceStrategyContext.getRequiredStatistics().runTime) {
       workerTasksUsage.runTime += message.taskRunTime ?? 0
-      if (workerTasksUsage.run !== 0) {
+      if (
+        this.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime &&
+        workerTasksUsage.run !== 0
+      ) {
         workerTasksUsage.avgRunTime =
           workerTasksUsage.runTime / workerTasksUsage.run
       }