fix: do not remove pool event user registered callbacks at destroy()
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 15 Mar 2024 19:07:10 +0000 (20:07 +0100)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Fri, 15 Mar 2024 19:07:10 +0000 (20:07 +0100)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
CHANGELOG.md
docs/api.md
src/pools/abstract-pool.ts
src/pools/pool.ts
tests/pools/cluster/dynamic.test.mjs
tests/pools/cluster/fixed.test.mjs
tests/pools/thread/dynamic.test.mjs
tests/pools/thread/fixed.test.mjs

index 7f1610253a7db9d839dd9d425d9081590669346f..0ee87abbf4f0e385484bbc870890962bf3802137 100644 (file)
@@ -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
index 6eead0f7fca23b7aa34cde75ec630f61589e2b99..5e4eeb227ff12b5d2c894f952ca6435d66cc0418 100644 (file)
@@ -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`
index c5ad9cb3608ac8e2095c23c023c949e0f48ae7eb..cd1d364d21c15db6cb9b5fae1e6af8e0029b2510 100644 (file)
@@ -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
index f6f3de36fe13ae6efced690a8637c431c4405a1d..1fa5b0f5e333a18c706d24705cc297b27d47d2ba 100644 (file)
@@ -244,7 +244,7 @@ export interface IPool<
    */
   readonly workerNodes: Array<IWorkerNode<Worker, Data>>
   /**
-   * 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:<PoolType>-<WorkerType>-pool`.
    *
    * Events that can currently be listened to:
index 8e6c125bf24a2bbd3d231968c1cb10756f12ae1e..8b6301c932aaea4f05972e12085c1509deec93d7 100644 (file)
@@ -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)
index cf00239514cd4864c297872dec4c42a2d5dea321..c36e7ce6b3b2fd9f73b45707774a985fa439a77f 100644 (file)
@@ -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)
index fbce8ae0030455ed70f7edcdba134c360bf68dd6..93f75af4247bb0c895869080bf250fc447c3ec52 100644 (file)
@@ -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)
index 94f7921caccb07d0474952a85c77e440d9d3fa0f..a17b8233697f5cd6836296eb93891b83f80f5da4 100644 (file)
@@ -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)