1 import { isMainThread
, parentPort
, workerData
} from
'worker_threads';
3 import ChargingStation from
'./ChargingStation';
4 import Utils from
'../utils/Utils';
5 import { WorkerEvents
} from
'../types/WorkerEvents';
8 // Add listener to start charging station from main thread
10 if (!Utils
.isUndefined(workerData
)) {
11 startChargingStation({ index
: workerData
.index
as number, templateFile
: workerData
.templateFile
as string });
15 function addListener() {
16 parentPort
.on('message', (message
) => {
17 if (message
.id
=== WorkerEvents
.START_WORKER_ELEMENT
) {
18 startChargingStation(message
.workerData
);
23 function startChargingStation(data
: any) {
24 const station
= new ChargingStation(data
.index
as number, data
.templateFile
as string);