Use object factory design pattern for code handling workers.
[e-mobility-charging-stations-simulator.git] / src / charging-station / StationWorker.ts
index 513265e2bb0679323adbbca9c2959c20d94b04be..32c75ca79724e114daad68c9cfb08e8459a92d70 100644 (file)
@@ -2,12 +2,14 @@ import { isMainThread, parentPort, workerData } from 'worker_threads';
 
 import ChargingStation from './ChargingStation';
 import Constants from '../utils/Constants';
+import Utils from '../utils/Utils';
 
 if (!isMainThread) {
-  startChargingStation({ index: workerData.index as number, templateFile: workerData.templateFile as string });
-
-  // Listener: start new charging station from main thread
+  // Add listener to start charging station from main thread
   addListener();
+  if (!Utils.isUndefined(workerData)) {
+    startChargingStation({ index: workerData.index as number, templateFile: workerData.templateFile as string });
+  }
 }
 
 function addListener() {