From: Jérôme Benoit Date: Tue, 3 Oct 2023 09:26:38 +0000 (+0200) Subject: feat: emit started/stopped event on worker set X-Git-Tag: v1.2.23~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=4c7c767b9ed625eee3e28f34bda8e63ecc4391b4;p=e-mobility-charging-stations-simulator.git feat: emit started/stopped event on worker set Signed-off-by: Jérôme Benoit --- diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 5f10f090..c5df860c 100644 --- a/src/worker/WorkerSet.ts +++ b/src/worker/WorkerSet.ts @@ -78,6 +78,7 @@ export class WorkerSet extends WorkerAbstract { // Add worker set element sequentially to optimize memory at startup this.workerOptions.workerStartDelay! > 0 && (await sleep(randomizeDelay(this.workerOptions.workerStartDelay!))); + this.emitter?.emit(WorkerSetEvents.started, this.info); this.started = true; } @@ -92,6 +93,7 @@ export class WorkerSet extends WorkerAbstract { }); await worker.terminate(); await waitWorkerExit; + this.emitter?.emit(WorkerSetEvents.stopped, this.info); this.emitter?.emitDestroy(); this.started = false; } diff --git a/src/worker/WorkerTypes.ts b/src/worker/WorkerTypes.ts index 806808d8..cfbe2dac 100644 --- a/src/worker/WorkerTypes.ts +++ b/src/worker/WorkerTypes.ts @@ -19,6 +19,8 @@ export interface SetInfo { } export enum WorkerSetEvents { + started = 'started', + stopped = 'stopped', error = 'error', elementStarted = 'elementStarted', elementError = 'elementError',