From ee60150ff976ab3689fbef317ca0574459a0a819 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Wed, 31 May 2023 22:29:56 +0200 Subject: [PATCH] refactor: throw error at simalator start/stop outside the main thread MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/Bootstrap.ts | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index dc1e2f1c..df0bb8e9 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -91,7 +91,10 @@ export class Bootstrap extends EventEmitter { } public async start(): Promise { - 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 { - 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( -- 2.34.1