From 83a3286a048e21e8e872e6438736b818584a16ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 26 Sep 2021 10:18:34 +0200 Subject: [PATCH] ATG: unify start/stop on connector API MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- .../AutomaticTransactionGenerator.ts | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) 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 }); } -- 2.34.1