From e6cf2a95dd56b9683ed81b622f5565c97a60e5a1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 28 Aug 2024 15:39:23 +0200 Subject: [PATCH] refactor: merge dynamic pool events emission code 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 | 7 ------- src/pools/cluster/dynamic.ts | 11 ++++++++--- src/pools/thread/dynamic.ts | 11 ++++++++--- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 8d8a750c..0503e891 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -934,12 +934,6 @@ export abstract class AbstractPool< return this.workerNodes.length <= 1 || this.info.queuedTasks === 0 } - private checkAndEmitEmptyEvent (): void { - if (this.emitter != null && this.empty) { - this.emitter.emit(PoolEvents.empty, this.info) - } - } - private checkAndEmitReadyEvent (): void { if (this.emitter != null && !this.readyEventEmitted && this.ready) { this.emitter.emit(PoolEvents.ready, this.info) @@ -1402,7 +1396,6 @@ export abstract class AbstractPool< this.workerChoiceStrategiesContext?.remove(workerNodeKey) workerNode.info.dynamic && this.checkAndEmitDynamicWorkerDestructionEvents() - this.checkAndEmitEmptyEvent() } } diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index acca81ba..9561fc80 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -52,9 +52,14 @@ export class DynamicClusterPool< /** @inheritDoc */ protected checkAndEmitDynamicWorkerDestructionEvents (): void { - if (this.emitter != null && this.fullEventEmitted && !this.full) { - this.emitter.emit(PoolEvents.fullEnd, this.info) - this.fullEventEmitted = false + if (this.emitter != null) { + if (this.fullEventEmitted && !this.full) { + this.emitter.emit(PoolEvents.fullEnd, this.info) + this.fullEventEmitted = false + } + if (this.empty) { + this.emitter.emit(PoolEvents.empty, this.info) + } } } diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index 8fd4b675..9cb068a2 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -52,9 +52,14 @@ export class DynamicThreadPool< /** @inheritDoc */ protected checkAndEmitDynamicWorkerDestructionEvents (): void { - if (this.emitter != null && this.fullEventEmitted && !this.full) { - this.emitter.emit(PoolEvents.fullEnd, this.info) - this.fullEventEmitted = false + if (this.emitter != null) { + if (this.fullEventEmitted && !this.full) { + this.emitter.emit(PoolEvents.fullEnd, this.info) + this.fullEventEmitted = false + } + if (this.empty) { + this.emitter.emit(PoolEvents.empty, this.info) + } } } -- 2.34.1