feat: add event emitter to worker pool/set code
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerDynamicPool.ts
index c8a87ceb2cda6716efeaf11fd7e99d3a53225d64..b7b39819e82ed7e67e45acafec8bd3b419f61686 100644 (file)
@@ -1,3 +1,4 @@
+import type EventEmitterAsyncResource from 'node:events';
 import type { Worker } from 'node:worker_threads';
 
 import { DynamicThreadPool, type ErrorHandler, type ExitHandler } from 'poolifier';
@@ -40,30 +41,21 @@ export class WorkerDynamicPool extends WorkerAbstract<WorkerData> {
     return undefined;
   }
 
-  /**
-   *
-   * @returns
-   * @public
-   */
+  get emitter(): EventEmitterAsyncResource | undefined {
+    return this.pool?.emitter;
+  }
+
+  /** @inheritDoc */
   public async start(): Promise<void> {
     // This is intentional
   }
 
-  /**
-   *
-   * @returns
-   * @public
-   */
+  /** @inheritDoc */
   public async stop(): Promise<void> {
     return this.pool.destroy();
   }
 
-  /**
-   *
-   * @param elementData -
-   * @returns
-   * @public
-   */
+  /** @inheritDoc */
   public async addElement(elementData: WorkerData): Promise<void> {
     await this.pool.execute(elementData);
     // Start element sequentially to optimize memory at startup