1 import { isMainThread
, parentPort
, workerData
} from
'worker_threads';
3 import ChargingStation from
'./ChargingStation';
4 import Constants from
'../utils/Constants';
7 const station
= new ChargingStation(workerData
.index
as number, workerData
.templateFile
as string);
10 // Listener: start new charging station from main thread
14 function addListener() {
15 parentPort
.setMaxListeners(Constants
.MAX_LISTENERS
);
16 parentPort
.on('message', (e
) => {
17 if (e
.id
=== Constants
.START_CHARGING_STATION
) {
18 startChargingStation(e
.workerData
);
23 function startChargingStation(data
: any) {
24 const station
= new ChargingStation(data
.index
as number, data
.templateFile
as string);