X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FBootstrap.ts;h=677843d27c1c479ac4c9e34f98bcd98f38a55a44;hb=fca8bc64968004b4018a4d766b2121ced4fee943;hp=db884ed874285adae8c532ff6b3fccb175ec5fbb;hpb=f130b8e620e8808516bbf80bc4247c81fae02186;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index db884ed8..677843d2 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -129,7 +129,7 @@ export class Bootstrap extends EventEmitter { public async stop(): Promise { if (isMainThread && this.started === true) { - await this.uiServer?.sendBroadcastChannelRequest( + await this.uiServer?.sendRequestOnBroadcastChannel( this.uiServer.buildProtocolRequest( Utils.generateUUID(), ProcedureName.STOP_CHARGING_STATION, @@ -299,18 +299,23 @@ export class Bootstrap extends EventEmitter { process.exit(0); }) .catch((error) => { - console.error(chalk.red('Error while stopping charging stations simulator:'), error); + console.error(chalk.red('Error while shutdowning charging stations simulator: '), error); process.exit(1); }); }; - 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); } }); });