From: Jérôme Benoit Date: Wed, 31 May 2023 20:29:56 +0000 (+0200) Subject: refactor: throw error at simalator start/stop outside the main thread X-Git-Tag: v1.2.16~27 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=ee60150ff976ab3689fbef317ca0574459a0a819;p=e-mobility-charging-stations-simulator.git refactor: throw error at simalator start/stop outside the main thread Signed-off-by: Jérôme Benoit --- 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(