build: cleanup eslint configuration
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerSet.ts
index 5f10f090eea99788893736243c32ced43f7958fd..17b5b6dde201c85f4c0af0cbaf3574d33968fb03 100644 (file)
@@ -78,6 +78,7 @@ export class WorkerSet extends WorkerAbstract<WorkerData> {
     // 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<WorkerData> {
       });
       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<WorkerData> {
     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();