From: Jérôme Benoit Date: Wed, 28 Aug 2024 13:39:23 +0000 (+0200) Subject: refactor: merge dynamic pool events emission code X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e6cf2a95dd56b9683ed81b622f5565c97a60e5a1;p=poolifier.git refactor: merge dynamic pool events emission code Signed-off-by: Jérôme Benoit --- 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) + } } }