+ private gracefulShutdown = (): void => {
+ console.info(`${chalk.green('Graceful shutdown')}`);
+ this.stop()
+ .then(() => {
+ process.exit(0);
+ })
+ .catch((error) => {
+ console.error(chalk.red('Error while shutdowning charging stations simulator: '), error);
+ process.exit(1);
+ });
+ };
+
+ 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 === stoppedEventsToWait) {
+ resolve(stoppedEvents);
+ }
+ });
+ });
+ };
+