X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FStationWorker.ts;h=dd0f377ceff295c7df8980ece4931d5545dfa9da;hb=81797102d5214fea2fc58eff2666fe8b8d9a5a11;hp=20fb27ca04ae47a533f7109525f07a8e7bba1768;hpb=3340259a3cd75024ae3510433f4bf4232c8de7fb;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/StationWorker.ts b/src/charging-station/StationWorker.ts index 20fb27ca..dd0f377c 100644 --- a/src/charging-station/StationWorker.ts +++ b/src/charging-station/StationWorker.ts @@ -1,4 +1,6 @@ -import { StationWorkerData, WorkerEvents } from '../types/Worker'; +// Partial Copyright Jerome Benoit. 2021. All Rights Reserved. + +import { StationWorkerData, WorkerEvents, WorkerMessage } from '../types/Worker'; import { parentPort, workerData } from 'worker_threads'; import ChargingStation from './ChargingStation'; @@ -19,18 +21,20 @@ if (Utils.workerPoolInUse()) { } /** - * + * Listen messages send by the main thread */ function addMessageListener(): void { - parentPort.on('message', (message) => { + parentPort?.on('message', (message: WorkerMessage) => { if (message.id === WorkerEvents.START_WORKER_ELEMENT) { - startChargingStation(message.workerData); + startChargingStation(message.data); } }); } /** - * @param data + * Create and start a charging station instance + * + * @param data workerData */ function startChargingStation(data: StationWorkerData): void { const station = new ChargingStation(data.index, data.templateFile);