X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerFactory.ts;h=0a532681cf9a12d41ffb0c73b13b3fd71c8643e7;hb=15ad763ee257fb7d6b767a6014c273f757641b02;hp=a6679cca73149c07fb6130feb6eb4f8bc62dfd80;hpb=6c1761d470507ea23d186be61b94ca7375c5144a;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index a6679cca..0a532681 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -1,15 +1,15 @@ -import { Worker, isMainThread } from 'worker_threads'; +import { type Worker, isMainThread } from 'node:worker_threads'; import type { PoolOptions } from 'poolifier'; -import { WorkerData, WorkerOptions, WorkerProcessType } from '../types/Worker'; -import type WorkerAbstract from './WorkerAbstract'; -import WorkerConstants from './WorkerConstants'; -import WorkerDynamicPool from './WorkerDynamicPool'; -import WorkerSet from './WorkerSet'; -import WorkerStaticPool from './WorkerStaticPool'; +import type { WorkerAbstract } from './WorkerAbstract'; +import { WorkerConstants } from './WorkerConstants'; +import { WorkerDynamicPool } from './WorkerDynamicPool'; +import { WorkerSet } from './WorkerSet'; +import { WorkerStaticPool } from './WorkerStaticPool'; +import { type WorkerData, type WorkerOptions, WorkerProcessType } from './WorkerTypes'; -export default class WorkerFactory { +export class WorkerFactory { private constructor() { // This is intentional } @@ -29,21 +29,20 @@ export default class WorkerFactory { workerOptions?.elementStartDelay ?? WorkerConstants.DEFAULT_ELEMENT_START_DELAY; workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as PoolOptions); workerOptions?.messageHandler && - // eslint-disable-next-line @typescript-eslint/no-misused-promises (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler); - let workerImplementation: WorkerAbstract = null; + let workerImplementation: WorkerAbstract | null = null; switch (workerProcessType) { - case WorkerProcessType.WORKER_SET: + case WorkerProcessType.workerSet: workerOptions.elementsPerWorker = workerOptions?.elementsPerWorker ?? WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER; workerImplementation = new WorkerSet(workerScript, workerOptions); break; - case WorkerProcessType.STATIC_POOL: + case WorkerProcessType.staticPool: workerOptions.poolMaxSize = workerOptions?.poolMaxSize ?? WorkerConstants.DEFAULT_POOL_MAX_SIZE; workerImplementation = new WorkerStaticPool(workerScript, workerOptions); break; - case WorkerProcessType.DYNAMIC_POOL: + case WorkerProcessType.dynamicPool: workerOptions.poolMinSize = workerOptions?.poolMinSize ?? WorkerConstants.DEFAULT_POOL_MIN_SIZE; workerOptions.poolMaxSize =