docs: add FIXME
[e-mobility-charging-stations-simulator.git] / src / charging-station / ChargingStationUtils.ts
index f86c5d783b82657c483183f9bf43c562e2c11de1..033fc4b36f79647746106169fe462834d241e463 100644 (file)
@@ -1,4 +1,5 @@
 import crypto from 'node:crypto';
+import type EventEmitter from 'node:events';
 import path from 'node:path';
 import { fileURLToPath } from 'node:url';
 
@@ -18,6 +19,7 @@ import {
   type ChargingSchedulePeriod,
   type ChargingStationInfo,
   type ChargingStationTemplate,
+  ChargingStationWorkerMessageEvents,
   ConnectorPhaseRotation,
   type ConnectorStatus,
   ConnectorStatusEnum,
@@ -539,6 +541,25 @@ export class ChargingStationUtils {
     );
   }
 
+  public static waitForChargingStationEvents = async (
+    emitter: EventEmitter,
+    event: ChargingStationWorkerMessageEvents,
+    eventsToWait: number
+  ): Promise<number> => {
+    return new Promise((resolve) => {
+      let events = 0;
+      if (eventsToWait === 0) {
+        resolve(events);
+      }
+      emitter.on(event, () => {
+        ++events;
+        if (events === eventsToWait) {
+          resolve(events);
+        }
+      });
+    });
+  };
+
   private static getConfiguredNumberOfConnectors(stationTemplate: ChargingStationTemplate): number {
     let configuredMaxConnectors: number;
     if (Utils.isNotEmptyArray(stationTemplate.numberOfConnectors) === true) {