X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerAbstract.ts;h=16d566bde2ae60049fe401c7f13f830af4ce17dd;hb=42486f2357b011f9244c6b29f4e05185138ce8d1;hp=1dd064fbf893023ed4f41b91c411f298de1cd1b1;hpb=44a95b7fc8487ae8116f89820ca03cb108dfada8;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 1dd064fb..16d566bd 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -1,19 +1,19 @@ -import { WorkerData, WorkerOptions } from '../types/Worker'; +import fs from 'node:fs'; -import WorkerConstants from './WorkerConstants'; -import fs from 'fs'; +import { WorkerConstants } from './WorkerConstants'; +import type { WorkerData, WorkerOptions } from './WorkerTypes'; -export default abstract class WorkerAbstract { +export abstract class WorkerAbstract { protected readonly workerScript: string; protected readonly workerOptions: WorkerOptions; public abstract readonly size: number; - public abstract readonly maxElementsPerWorker: number | null; + public abstract readonly maxElementsPerWorker: number | undefined; /** * `WorkerAbstract` constructor. * - * @param workerScript - * @param workerOptions + * @param workerScript - + * @param workerOptions - */ constructor( workerScript: string, @@ -24,14 +24,15 @@ export default abstract class WorkerAbstract { poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE, elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER, poolOptions: {}, - messageHandler: () => { - /* This is intentional */ - }, + messageHandler: WorkerConstants.EMPTY_FUNCTION, } ) { - if (!workerScript) { + if (workerScript === null || workerScript === undefined) { throw new Error('Worker script is not defined'); } + if (typeof workerScript === 'string' && workerScript.trim().length === 0) { + throw new Error('Worker script is empty'); + } if (!fs.existsSync(workerScript)) { throw new Error('Worker script file does not exist'); }