From 5f14c60844e65158b77170ae7f361ffbdf71c57e Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 26 Mar 2026 17:42:21 +0100 Subject: [PATCH] fix: respect elementAddDelay by using sequential startup when configured MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit The perf commit 218fd550 switched to parallel Promise.allSettled for startup speed, but broke elementAddDelay since all stations launched simultaneously. Now uses sequential await loop when elementAddDelay > 0 and parallel allSettled when 0 or unset. Removes redundant outer try/catch — config errors propagate as fatal, station errors are handled per-station in both paths. --- src/charging-station/Bootstrap.ts | 36 +++++++++++++++++++------------ 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/src/charging-station/Bootstrap.ts b/src/charging-station/Bootstrap.ts index e232f291..80df1fa5 100644 --- a/src/charging-station/Bootstrap.ts +++ b/src/charging-station/Bootstrap.ts @@ -239,15 +239,30 @@ export class Bootstrap extends EventEmitter { // Start ChargingStation object instance in worker thread // eslint-disable-next-line @typescript-eslint/no-non-null-assertion for (const stationTemplateUrl of Configuration.getStationTemplateUrls()!) { - try { - const nbStations = stationTemplateUrl.numberOfStations - const addChargingStationTasks: Promise[] = [] + const nbStations = stationTemplateUrl.numberOfStations + const sequentialAdd = + (Configuration.getConfigurationSection( + ConfigurationSection.worker + ).elementAddDelay ?? 0) > 0 + if (sequentialAdd) { for (let index = 1; index <= nbStations; index++) { - addChargingStationTasks.push( - this.addChargingStation(index, stationTemplateUrl.file) - ) + try { + await this.addChargingStation(index, stationTemplateUrl.file) + } catch (error) { + console.error( + chalk.red( + `Error at starting charging station with template file ${stationTemplateUrl.file}: ` + ), + error + ) + } } - const results = await Promise.allSettled(addChargingStationTasks) + } else { + const results = await Promise.allSettled( + Array.from({ length: nbStations }, (_, i) => + this.addChargingStation(i + 1, stationTemplateUrl.file) + ) + ) for (const result of results) { if (result.status === 'rejected') { console.error( @@ -258,13 +273,6 @@ export class Bootstrap extends EventEmitter { ) } } - } catch (error) { - console.error( - chalk.red( - `Error at starting charging station with template file ${stationTemplateUrl.file}: ` - ), - error - ) } } const workerConfiguration = Configuration.getConfigurationSection( -- 2.43.0