Cleanups.
[e-mobility-charging-stations-simulator.git] / src / charging-station / StationWorker.ts
CommitLineData
3d2ff9e4 1import { isMainThread, parentPort, workerData } from 'worker_threads';
3f40bc9c 2
6af9012e 3import ChargingStation from './ChargingStation';
5fdab605 4import Constants from '../utils/Constants';
7dde0b73
JB
5
6if (!isMainThread) {
ad3de6c4 7 const station = new ChargingStation(workerData.index as number, workerData.templateFile as string);
7dde0b73 8 station.start();
3d2ff9e4
J
9
10 // Listener: start new charging station from main thread
11 addListener();
12}
13
14function addListener() {
5fdab605
JB
15 parentPort.setMaxListeners(Constants.MAX_LISTENERS);
16 parentPort.on('message', (e) => {
17 if (e.id === Constants.START_CHARGING_STATION) {
18 startChargingStation(e.workerData);
3d2ff9e4
J
19 }
20 });
21}
22
23function startChargingStation(data: any) {
24 const station = new ChargingStation(data.index as number, data.templateFile as string);
25 station.start();
7dde0b73 26}