X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerSet.ts;h=17b5b6dde201c85f4c0af0cbaf3574d33968fb03;hb=a78c196b969380d9d968c94fab567b0be6828f69;hp=5f10f090eea99788893736243c32ced43f7958fd;hpb=38b2428f0046c84963f4e873b76bc440155da0f2;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerSet.ts b/src/worker/WorkerSet.ts index 5f10f090..17b5b6dd 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,7 +93,9 @@ export class WorkerSet extends WorkerAbstract { }); await worker.terminate(); await waitWorkerExit; + this.emitter?.emit(WorkerSetEvents.stopped, this.info); this.emitter?.emitDestroy(); + this.emitter?.removeAllListeners(); this.started = false; } } @@ -102,7 +105,7 @@ export class WorkerSet extends WorkerAbstract { if (!this.started) { throw new Error('Cannot add a WorkerSet element: not started'); } - if (!this.workerSet) { + if (this.workerSet == null) { throw new Error("Cannot add a WorkerSet element: 'workerSet' property does not exist"); } const workerSetElement = await this.getWorkerSetElement();