refactor: move back pressure event emission in the helper
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 18 Aug 2023 22:46:57 +0000 (00:46 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 18 Aug 2023 22:46:57 +0000 (00:46 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/abstract-pool.ts

index dc1fc53f90bfbda6031a56cfd2c92e62867f07ec..7ed6ab0351f3ad1cf44c6961b1273a2d78fc593f 100644 (file)
@@ -1229,6 +1229,9 @@ export abstract class AbstractPool<
       if (this.type === PoolTypes.dynamic && this.full) {
         this.emitter.emit(PoolEvents.full, this.info)
       }
+      if (this.hasBackPressure()) {
+        this.emitter.emit(PoolEvents.backPressure, this.info)
+      }
     }
   }
 
@@ -1309,11 +1312,7 @@ export abstract class AbstractPool<
   }
 
   private enqueueTask (workerNodeKey: number, task: Task<Data>): number {
-    const tasksQueueSize = this.workerNodes[workerNodeKey].enqueueTask(task)
-    if (this.hasBackPressure()) {
-      this.emitter?.emit(PoolEvents.backPressure, this.info)
-    }
-    return tasksQueueSize
+    return this.workerNodes[workerNodeKey].enqueueTask(task)
   }
 
   private dequeueTask (workerNodeKey: number): Task<Data> | undefined {