From: Jérôme Benoit Date: Fri, 26 May 2023 11:20:55 +0000 (+0200) Subject: fix: ensure simulator stop wait for started CS only stop X-Git-Tag: v1.2.14~5 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=805e8a892d75e4bd8b75f5b7c76110bde0e2dc81;p=e-mobility-charging-stations-simulator.git fix: ensure simulator stop wait for started CS only stop Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index db884ed8..96a498f6 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -304,13 +304,18 @@ export class Bootstrap extends EventEmitter { }); }; - private waitForChargingStationsStopped = async (): Promise => { + private waitForChargingStationsStopped = async ( + stoppedEventsToWait = this.numberOfStartedChargingStations + ): Promise => { return new Promise((resolve) => { let stoppedEvents = 0; + if (stoppedEventsToWait === 0) { + resolve(stoppedEvents); + } this.on(ChargingStationWorkerMessageEvents.stopped, () => { ++stoppedEvents; - if (stoppedEvents === this.numberOfChargingStations) { - resolve(); + if (stoppedEvents === stoppedEventsToWait) { + resolve(stoppedEvents); } }); });