X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FChargingStationWorker.ts;h=042d3d5bfc2b3bc913484c5a0f5d0982b982148f;hb=3b09e788c6dab8e5a8b3314e8e69ede16ff82fcc;hp=35a7e534353f5ffaafbae6daba93948e9803d407;hpb=8ae4dcf159bf29835de7fd1edd7978aa8a3ee76b;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/ChargingStationWorker.ts b/src/charging-station/ChargingStationWorker.ts index 35a7e534..042d3d5b 100644 --- a/src/charging-station/ChargingStationWorker.ts +++ b/src/charging-station/ChargingStationWorker.ts @@ -6,23 +6,24 @@ import { ThreadWorker } from 'poolifier' import { BaseError } from '../exception/index.js' import type { - ChargingStationData, + ChargingStationInfo, ChargingStationWorkerData, ChargingStationWorkerEventError, ChargingStationWorkerMessage } from '../types/index.js' -import { buildChargingStationDataPayload, Configuration } from '../utils/index.js' +import { Configuration } from '../utils/index.js' import { type WorkerMessage, WorkerMessageEvents } from '../worker/index.js' import { ChargingStation } from './ChargingStation.js' export let chargingStationWorker: object if (Configuration.workerPoolInUse()) { - chargingStationWorker = new ThreadWorker( - (data?: ChargingStationWorkerData): void => { - // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, no-new - new ChargingStation(data!.index, data!.templateFile, data!.options) - } - ) + chargingStationWorker = new ThreadWorker< + ChargingStationWorkerData, + ChargingStationInfo | undefined + >((data?: ChargingStationWorkerData): ChargingStationInfo | undefined => { + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, no-new + return new ChargingStation(data!.index, data!.templateFile, data!.options).stationInfo + }) } else { // eslint-disable-next-line @typescript-eslint/no-extraneous-class class ChargingStationWorker { @@ -38,13 +39,14 @@ if (Configuration.workerPoolInUse()) { ) parentPort?.postMessage({ event: WorkerMessageEvents.addedWorkerElement, - data: buildChargingStationDataPayload(chargingStation) - } satisfies ChargingStationWorkerMessage) + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + data: chargingStation.stationInfo! + } satisfies ChargingStationWorkerMessage) } catch (error) { parentPort?.postMessage({ event: WorkerMessageEvents.workerElementError, data: { - event: WorkerMessageEvents.addWorkerElement, + event: message.event, name: (error as Error).name, message: (error as Error).message, stack: (error as Error).stack