From: Jérôme Benoit Date: Fri, 15 Mar 2024 19:07:10 +0000 (+0100) Subject: fix: do not remove pool event user registered callbacks at destroy() X-Git-Tag: v3.1.22~3 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d67bed32f766d3db7c436ce1a1b9b8dfc3f4633a;p=poolifier.git fix: do not remove pool event user registered callbacks at destroy() Signed-off-by: Jérôme Benoit --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 7f161025..0ee87abb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix pool event emitter registered callbacks removal at `destroy()`. + ## [3.1.21] - 2024-02-22 ### Fixed diff --git a/docs/api.md b/docs/api.md index 6eead0f7..5e4eeb22 100644 --- a/docs/api.md +++ b/docs/api.md @@ -123,7 +123,7 @@ An object with these properties: Default: `true` - `restartWorkerOnError` (optional) - Restart worker on uncaught error in this pool. Default: `true` -- `enableEvents` (optional) - Events integrated with async resource emission enablement in this pool. +- `enableEvents` (optional) - Pool events integrated with async resource emission enablement. Default: `true` - `enableTasksQueue` (optional) - Tasks queue per worker enablement in this pool. Default: `false` diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index c5ad9cb3..cd1d364d 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -993,7 +993,6 @@ export abstract class AbstractPool< ) this.emitter?.emit(PoolEvents.destroy, this.info) this.emitter?.emitDestroy() - this.emitter?.removeAllListeners() this.readyEventEmitted = false this.destroying = false this.started = false diff --git a/src/pools/pool.ts b/src/pools/pool.ts index f6f3de36..1fa5b0f5 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -244,7 +244,7 @@ export interface IPool< */ readonly workerNodes: Array> /** - * Event emitter integrated with async resource on which events can be listened to. + * Pool event emitter integrated with async resource. * The async tracking tooling identifier is `poolifier:--pool`. * * Events that can currently be listened to: diff --git a/tests/pools/cluster/dynamic.test.mjs b/tests/pools/cluster/dynamic.test.mjs index 8e6c125b..8b6301c9 100644 --- a/tests/pools/cluster/dynamic.test.mjs +++ b/tests/pools/cluster/dynamic.test.mjs @@ -72,7 +72,7 @@ describe('Dynamic cluster pool test suite', () => { await pool.destroy() const numberOfExitEvents = await exitPromise expect(pool.started).toBe(false) - expect(pool.emitter.eventNames()).toStrictEqual([]) + expect(pool.emitter.eventNames()).toStrictEqual(['busy', 'destroy']) expect(pool.readyEventEmitted).toBe(false) expect(pool.workerNodes.length).toBe(0) expect(numberOfExitEvents).toBe(min) diff --git a/tests/pools/cluster/fixed.test.mjs b/tests/pools/cluster/fixed.test.mjs index cf002395..c36e7ce6 100644 --- a/tests/pools/cluster/fixed.test.mjs +++ b/tests/pools/cluster/fixed.test.mjs @@ -270,7 +270,7 @@ describe('Fixed cluster pool test suite', () => { await pool.destroy() const numberOfExitEvents = await exitPromise expect(pool.started).toBe(false) - expect(pool.emitter.eventNames()).toStrictEqual([]) + expect(pool.emitter.eventNames()).toStrictEqual(['busy', 'destroy']) expect(pool.readyEventEmitted).toBe(false) expect(pool.workerNodes.length).toBe(0) expect(numberOfExitEvents).toBe(numberOfWorkers) diff --git a/tests/pools/thread/dynamic.test.mjs b/tests/pools/thread/dynamic.test.mjs index fbce8ae0..93f75af4 100644 --- a/tests/pools/thread/dynamic.test.mjs +++ b/tests/pools/thread/dynamic.test.mjs @@ -72,7 +72,7 @@ describe('Dynamic thread pool test suite', () => { await pool.destroy() const numberOfExitEvents = await exitPromise expect(pool.started).toBe(false) - expect(pool.emitter.eventNames()).toStrictEqual([]) + expect(pool.emitter.eventNames()).toStrictEqual(['busy', 'destroy']) expect(pool.readyEventEmitted).toBe(false) expect(pool.workerNodes.length).toBe(0) expect(numberOfExitEvents).toBe(min) diff --git a/tests/pools/thread/fixed.test.mjs b/tests/pools/thread/fixed.test.mjs index 94f7921c..a17b8233 100644 --- a/tests/pools/thread/fixed.test.mjs +++ b/tests/pools/thread/fixed.test.mjs @@ -301,7 +301,7 @@ describe('Fixed thread pool test suite', () => { await pool.destroy() const numberOfExitEvents = await exitPromise expect(pool.started).toBe(false) - expect(pool.emitter.eventNames()).toStrictEqual([]) + expect(pool.emitter.eventNames()).toStrictEqual(['busy', 'destroy']) expect(pool.readyEventEmitted).toBe(false) expect(pool.workerNodes.length).toBe(0) expect(numberOfExitEvents).toBe(numberOfThreads)