Storage: use worker threads message passing to store performance records from
[e-mobility-charging-stations-simulator.git] / src / charging-station / StationWorker.ts
index c3c5cb51346ce2f36f843f816c29eb27abbdb524..dd0f377ceff295c7df8980ece4931d5545dfa9da 100644 (file)
@@ -1,6 +1,6 @@
 // Partial Copyright Jerome Benoit. 2021. All Rights Reserved.
 
-import { StationWorkerData, WorkerEvents } from '../types/Worker';
+import { StationWorkerData, WorkerEvents, WorkerMessage } from '../types/Worker';
 import { parentPort, workerData } from 'worker_threads';
 
 import ChargingStation from './ChargingStation';
@@ -24,9 +24,9 @@ if (Utils.workerPoolInUse()) {
  * Listen messages send by the main thread
  */
 function addMessageListener(): void {
-  parentPort?.on('message', (message) => {
+  parentPort?.on('message', (message: WorkerMessage) => {
     if (message.id === WorkerEvents.START_WORKER_ELEMENT) {
-      startChargingStation(message.workerData);
+      startChargingStation(message.data);
     }
   });
 }
@@ -34,7 +34,7 @@ function addMessageListener(): void {
 /**
  * Create and start a charging station instance
  *
- * @param {StationWorkerData} data workerData
+ * @param data workerData
  */
 function startChargingStation(data: StationWorkerData): void {
   const station = new ChargingStation(data.index, data.templateFile);