X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerAbstract.ts;h=cd4dedf992fca40ff0b7cb787e91468d28020d55;hb=6a4032b5d8f3cbaa18d3beddcdfe9d335c1cba90;hp=32319ab2ee87d6faf8af97a2dfcd9c74babaa9fc;hpb=4a3807d16c54137840a60af41877f3b21de12950;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 32319ab2..cd4dedf9 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -1,7 +1,7 @@ -import type { EventEmitter } from 'node:events'; +import type { EventEmitterAsyncResource } from 'node:events'; import { existsSync } from 'node:fs'; -import type { PoolEmitter, PoolInfo } from 'poolifier'; +import type { PoolInfo } from 'poolifier'; import type { SetInfo, WorkerData, WorkerOptions } from './WorkerTypes'; import { defaultErrorHandler, defaultExitHandler } from './WorkerUtils'; @@ -12,7 +12,7 @@ export abstract class WorkerAbstract { public abstract readonly info: PoolInfo | SetInfo; public abstract readonly size: number; public abstract readonly maxElementsPerWorker: number | undefined; - public abstract readonly emitter: EventEmitter | PoolEmitter | undefined; + public abstract readonly emitter: EventEmitterAsyncResource | undefined; /** * `WorkerAbstract` constructor. @@ -21,11 +21,14 @@ export abstract class WorkerAbstract { * @param workerOptions - */ constructor(workerScript: string, workerOptions: WorkerOptions) { - if (workerScript === null || workerScript === undefined) { - throw new Error('Worker script is not defined'); + if (workerScript == null) { + throw new TypeError('Worker script is not defined'); } - if (typeof workerScript === 'string' && workerScript.trim().length === 0) { - throw new Error('Worker script is empty'); + if (typeof workerScript !== 'string') { + throw new TypeError('Worker script must be a string'); + } + if (workerScript.trim().length === 0) { + throw new Error('Worker script is an empty string'); } if (!existsSync(workerScript)) { throw new Error('Worker script file does not exist');