From: Jérôme Benoit Date: Thu, 20 Jul 2023 19:48:08 +0000 (+0200) Subject: feat: add worker set events X-Git-Tag: v1.2.20~177 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c26984f2a8831eeb78ce791837f0032fd4bc8824;p=e-mobility-charging-stations-simulator.git feat: add worker set events Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 19ed8393..bc1a4c08 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -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 { 'message', this.workerOptions.poolOptions?.messageHandler ?? WorkerConstants.EMPTY_FUNCTION, ); + worker.on('message', (message: WorkerMessage) => { + 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, diff --git a/src/worker/WorkerTypes.ts b/src/worker/WorkerTypes.ts index 653cfedf..12d5ab26 100644 --- a/src/worker/WorkerTypes.ts +++ b/src/worker/WorkerTypes.ts @@ -20,6 +20,8 @@ export interface SetInfo { export enum WorkerSetEvents { error = 'error', + elementStarted = 'elementStarted', + elementError = 'elementError', } export const WorkerEvents = {