public async stop(): Promise<void> {
if (isMainThread && this.started === true) {
- await this.uiServer?.sendBroadcastChannelRequest(
+ await this.uiServer?.sendRequestOnBroadcastChannel(
this.uiServer.buildProtocolRequest(
Utils.generateUUID(),
ProcedureName.STOP_CHARGING_STATION,
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<void> => {
+ private waitForChargingStationsStopped = async (
+ stoppedEventsToWait = this.numberOfStartedChargingStations
+ ): Promise<number> => {
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);
}
});
});