X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationWorker.ts;h=4361ab9badd0a6f0e6d80b82f16e62a8fed0a804;hb=481c3802ecbdb0ae3cf75e028c7236f6b9b12671;hp=c720b21980ae6ad2cf9165054a949c122c27061b;hpb=721646e902fa12d165d4a1da06fb963fb30dc9f2;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index c720b219..4361ab9b 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -9,6 +9,27 @@ import type { ChargingStationWorkerData } from '../types'; import { Utils } from '../utils'; import { WorkerConstants, type WorkerMessage, WorkerMessageEvents } from '../worker'; +/** + * Create and start a charging station instance + * + * @param data - workerData + */ +const startChargingStation = (data: ChargingStationWorkerData): void => { + const station = new ChargingStation(data.index, data.templateFile); + station.start(); +}; + +/** + * Listen messages send by the main thread + */ +const addMessageListener = (): void => { + parentPort?.on('message', (message: WorkerMessage) => { + if (message.id === WorkerMessageEvents.startWorkerElement) { + startChargingStation(message.data); + } + }); +}; + // Conditionally export ThreadWorker instance for pool usage export let threadWorker: ThreadWorker; if (ChargingStationUtils.workerPoolInUse()) { @@ -23,24 +44,3 @@ if (ChargingStationUtils.workerPoolInUse()) { startChargingStation(workerData as ChargingStationWorkerData); } } - -/** - * Listen messages send by the main thread - */ -function addMessageListener(): void { - parentPort?.on('message', (message: WorkerMessage) => { - if (message.id === WorkerMessageEvents.startWorkerElement) { - startChargingStation(message.data); - } - }); -} - -/** - * Create and start a charging station instance - * - * @param data - workerData - */ -function startChargingStation(data: ChargingStationWorkerData): void { - const station = new ChargingStation(data.index, data.templateFile); - station.start(); -}