feat: add worker set events
authorJérôme Benoit <jerome.benoit@sap.com>
Thu, 20 Jul 2023 19:48:08 +0000 (21:48 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Thu, 20 Jul 2023 19:48:08 +0000 (21:48 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/worker/WorkerSet.ts
src/worker/WorkerTypes.ts

index 19ed8393f171a64d37e4e3d3e871cacf81f17539..bc1a4c0871547b5485d7ab8c443733741e90d8c3 100644 (file)
@@ -10,6 +10,7 @@ import { WorkerConstants } from './WorkerConstants';
 import {
   type SetInfo,
   type WorkerData,
+  type WorkerMessage,
   WorkerMessageEvents,
   type WorkerOptions,
   type WorkerSetElement,
@@ -116,6 +117,13 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
       'message',
       this.workerOptions.poolOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION,
     );
+    worker.on('message', (message: WorkerMessage<WorkerData>) => {
+      if (message.event === WorkerMessageEvents.startedWorkerElement) {
+        this.emitter?.emit(WorkerSetEvents.elementStarted, message.data);
+      } else if (message.event === WorkerMessageEvents.startWorkerElementError) {
+        this.emitter?.emit(WorkerSetEvents.elementError, message.data);
+      }
+    });
     worker.on(
       'error',
       this.workerOptions.poolOptions?.errorHandler ?? WorkerConstants.EMPTY_FUNCTION,
index 653cfedf66d58c4855387da0393f03b97e9b8af8..12d5ab26f13f7d62c408f20a8f55f09b862ca7b5 100644 (file)
@@ -20,6 +20,8 @@ export interface SetInfo {
 
 export enum WorkerSetEvents {
   error = 'error',
+  elementStarted = 'elementStarted',
+  elementError = 'elementError',
 }
 
 export const WorkerEvents = {