X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerAbstract.ts;h=2f9093f294de59fa3ddc1363f9310de9d98c70b5;hb=5edd8ba0f8978cfb3ca9d80f299d9748c6c5970e;hp=0ef5470649c2e943e0ff7134cb89b9a3ed29ae3a;hpb=be245fdab36274873e0a9651589cebd097548076;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerAbstract.ts b/src/worker/WorkerAbstract.ts index 0ef54706..2f9093f2 100644 --- a/src/worker/WorkerAbstract.ts +++ b/src/worker/WorkerAbstract.ts @@ -1,8 +1,8 @@ -import type EventEmitterAsyncResource from 'node:events'; -import fs from 'node:fs'; +import type { EventEmitter } from 'node:events'; +import { existsSync } from 'node:fs'; import type { Worker } from 'node:worker_threads'; -import type { ErrorHandler, ExitHandler, PoolInfo } from 'poolifier'; +import type { ErrorHandler, ExitHandler, PoolEmitter, PoolInfo } from 'poolifier'; import { WorkerConstants } from './WorkerConstants'; import type { SetInfo, WorkerData, WorkerOptions } from './WorkerTypes'; @@ -14,7 +14,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: EventEmitterAsyncResource | undefined; + public abstract readonly emitter: EventEmitter | PoolEmitter | undefined; /** * `WorkerAbstract` constructor. @@ -31,7 +31,7 @@ export abstract class WorkerAbstract { poolMaxSize: WorkerConstants.DEFAULT_POOL_MAX_SIZE, elementsPerWorker: WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER, poolOptions: {}, - } + }, ) { if (workerScript === null || workerScript === undefined) { throw new Error('Worker script is not defined'); @@ -39,7 +39,7 @@ export abstract class WorkerAbstract { if (typeof workerScript === 'string' && workerScript.trim().length === 0) { throw new Error('Worker script is empty'); } - if (!fs.existsSync(workerScript)) { + if (!existsSync(workerScript)) { throw new Error('Worker script file does not exist'); } this.workerScript = workerScript; @@ -55,15 +55,15 @@ export abstract class WorkerAbstract { } /** - * Start the worker pool/set. + * Starts the worker pool/set. */ public abstract start(): Promise; /** - * Stop the worker pool/set. + * Stops the worker pool/set. */ public abstract stop(): Promise; /** - * Add a task element to the worker pool/set. + * Adds a task element to the worker pool/set. * * @param elementData - */