Skip to content

Commit 2babd9d

Browse files
committed
refactor: merge dynamic pool events emission code
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
1 parent 5415178 commit 2babd9d

File tree

2 files changed

+12
-14
lines changed

2 files changed

+12
-14
lines changed

src/pools/abstract-pool.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2184,14 +2184,6 @@ export abstract class AbstractPool<
21842184
return workerNodeKey
21852185
}
21862186

2187-
private checkAndEmitEmptyEvent(): void {
2188-
if (this.eventTarget != null && this.empty) {
2189-
this.eventTarget.dispatchEvent(
2190-
new CustomEvent<PoolInfo>(PoolEvents.empty, { detail: this.info }),
2191-
)
2192-
}
2193-
}
2194-
21952187
/**
21962188
* Removes the worker node from the pool worker nodes.
21972189
*
@@ -2204,7 +2196,6 @@ export abstract class AbstractPool<
22042196
this.workerChoiceStrategiesContext?.remove(workerNodeKey)
22052197
workerNode.info.dynamic &&
22062198
this.checkAndEmitDynamicWorkerDestructionEvents()
2207-
this.checkAndEmitEmptyEvent()
22082199
}
22092200
}
22102201

src/pools/thread/dynamic.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,18 @@ export class DynamicThreadPool<
6161

6262
/** @inheritDoc */
6363
protected checkAndEmitDynamicWorkerDestructionEvents(): void {
64-
if (this.eventTarget != null && this.fullEventEmitted && !this.full) {
65-
this.eventTarget.dispatchEvent(
66-
new CustomEvent<PoolInfo>(PoolEvents.fullEnd, { detail: this.info }),
67-
)
68-
this.fullEventEmitted = false
64+
if (this.eventTarget != null) {
65+
if (this.fullEventEmitted && !this.full) {
66+
this.eventTarget.dispatchEvent(
67+
new CustomEvent<PoolInfo>(PoolEvents.fullEnd, { detail: this.info }),
68+
)
69+
this.fullEventEmitted = false
70+
}
71+
if (this.empty) {
72+
this.eventTarget.dispatchEvent(
73+
new CustomEvent<PoolInfo>(PoolEvents.empty, { detail: this.info }),
74+
)
75+
}
6976
}
7077
}
7178

0 commit comments

Comments
 (0)