From cb9b167557f9a903021bca1c7aba9fc9b24ae1b1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 19 Aug 2023 00:46:57 +0200 Subject: [PATCH] refactor: move back pressure event emission in the helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index dc1fc53f..7ed6ab03 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -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): 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 | undefined { -- 2.34.1