Cleanup workers handling classes.
[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) {
97ed5cec 7 startChargingStation({ index: workerData.index as number, templateFile: workerData.templateFile as string });
3d2ff9e4
J
8
9 // Listener: start new charging station from main thread
10 addListener();
11}
12
13function addListener() {
5fdab605 14 parentPort.on('message', (e) => {
97ed5cec 15 if (e.id === Constants.START_WORKER_ELEMENT) {
5fdab605 16 startChargingStation(e.workerData);
3d2ff9e4
J
17 }
18 });
19}
20
21function startChargingStation(data: any) {
22 const station = new ChargingStation(data.index as number, data.templateFile as string);
23 station.start();
7dde0b73 24}