fix: ensure firmware update simulation always run as async resource
[e-mobility-charging-stations-simulator.git] / src / charging-station / Bootstrap.ts
index dc1e2f1cab9c360b673d06d30382add0f02b6827..df0bb8e98cda7c85b30104ba9ed9fac37fceb610 100644 (file)
@@ -91,7 +91,10 @@ export class Bootstrap extends EventEmitter {
   }
 
   public async start(): Promise<void> {
-    if (isMainThread && this.started === false) {
+    if (!isMainThread) {
+      throw new Error('Cannot start charging stations simulator from worker thread');
+    }
+    if (this.started === false) {
       if (this.starting === false) {
         this.starting = true;
         this.initializeCounters();
@@ -145,7 +148,10 @@ export class Bootstrap extends EventEmitter {
   }
 
   public async stop(): Promise<void> {
-    if (isMainThread && this.started === true) {
+    if (!isMainThread) {
+      throw new Error('Cannot stop charging stations simulator from worker thread');
+    }
+    if (this.started === true) {
       if (this.stopping === false) {
         this.stopping = true;
         await this.uiServer?.sendInternalRequest(