From: Jérôme Benoit Date: Sun, 26 Sep 2021 08:18:34 +0000 (+0200) Subject: ATG: unify start/stop on connector API X-Git-Tag: v1.1.10~2 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=83a3286a048e21e8e872e6438736b818584a16ea;p=e-mobility-charging-stations-simulator.git ATG: unify start/stop on connector API Signed-off-by: Jérôme Benoit --- diff --git a/src/charging-station/AutomaticTransactionGenerator.ts b/src/charging-station/AutomaticTransactionGenerator.ts index 5fcf83a6..7645e27e 100644 --- a/src/charging-station/AutomaticTransactionGenerator.ts +++ b/src/charging-station/AutomaticTransactionGenerator.ts @@ -43,10 +43,7 @@ export default class AutomaticTransactionGenerator { for (const connector in this.chargingStation.connectors) { const connectorId = Utils.convertToInt(connector); if (connectorId > 0) { - // Avoid hogging the event loop with a busy loop - setImmediate(() => { - this.startConnector(connectorId).catch(() => { /* This is intentional */ }); - }); + this.startConnector(connectorId); } } } @@ -60,7 +57,7 @@ export default class AutomaticTransactionGenerator { } } - private async startConnector(connectorId: number): Promise { + private async internalStartConnector(connectorId: number): Promise { this.initStartConnectorStatus(connectorId); logger.info(this.logPrefix(connectorId) + ' started on connector and will run for ' + Utils.formatDurationMilliSeconds(this.connectorsStatus.get(connectorId).stopDate.getTime() - this.connectorsStatus.get(connectorId).startDate.getTime())); while (this.connectorsStatus.get(connectorId).start) { @@ -124,6 +121,13 @@ export default class AutomaticTransactionGenerator { logger.debug(`${this.logPrefix(connectorId)} connector status %j`, this.connectorsStatus.get(connectorId)); } + private startConnector(connectorId: number): void { + // Avoid hogging the event loop with a busy loop + setImmediate(() => { + this.internalStartConnector(connectorId).catch(() => { /* This is intentional */ }); + }); + } + private stopConnector(connectorId: number): void { this.connectorsStatus.set(connectorId, { ...this.connectorsStatus.get(connectorId), start: false }); }