X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerAbstract.ts;h=16d566bde2ae60049fe401c7f13f830af4ce17dd;hb=4c8782eeb15a7c41b4ef5a413768abd47615047a;hp=356e1a7ab8997c2dac8eeab4c03e4c09f0fac0e1;hpb=0e4fa348298d36900560f7466f21f44090d2fe1b;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 356e1a7a..16d566bd 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -1,13 +1,13 @@ -import fs from 'fs'; +import fs from 'node:fs'; -import type { WorkerData, WorkerOptions } from '../types/Worker'; -import WorkerConstants from './WorkerConstants'; +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. @@ -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'); }