refactor: throw error at simalator start/stop outside the main thread
authorJérôme Benoit <jerome.benoit@sap.com>
Wed, 31 May 2023 20:29:56 +0000 (22:29 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Wed, 31 May 2023 20:29:56 +0000 (22:29 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
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(