X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerFactory.ts;h=d248d3bab765b5aabad6e9d5e2afb5dc773c5df0;hb=d181b12b516b58fc80cbd5300570612e6b025024;hp=f64d27810ed04a3e2a7752918f94d0ea3b7ec006;hpb=5edd8ba0f8978cfb3ca9d80f299d9748c6c5970e;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index f64d2781..d248d3ba 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -1,12 +1,10 @@ import { isMainThread } from 'node:worker_threads'; -import type { ThreadPoolOptions } from 'poolifier'; - import type { WorkerAbstract } from './WorkerAbstract'; -import { WorkerConstants } from './WorkerConstants'; +import { DEFAULT_WORKER_OPTIONS } from './WorkerConstants'; import { WorkerDynamicPool } from './WorkerDynamicPool'; +import { WorkerFixedPool } from './WorkerFixedPool'; import { WorkerSet } from './WorkerSet'; -import { WorkerStaticPool } from './WorkerStaticPool'; import { type WorkerData, type WorkerOptions, WorkerProcessType } from './WorkerTypes'; export class WorkerFactory { @@ -22,29 +20,16 @@ export class WorkerFactory { if (!isMainThread) { throw new Error('Cannot get a worker implementation outside the main thread'); } - workerOptions = workerOptions ?? ({} as WorkerOptions); - workerOptions.workerStartDelay = - workerOptions?.workerStartDelay ?? WorkerConstants.DEFAULT_WORKER_START_DELAY; - workerOptions.elementStartDelay = - workerOptions?.elementStartDelay ?? WorkerConstants.DEFAULT_ELEMENT_START_DELAY; - workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as ThreadPoolOptions); + workerOptions = { ...DEFAULT_WORKER_OPTIONS, ...workerOptions }; let workerImplementation: WorkerAbstract | null = null; switch (workerProcessType) { case WorkerProcessType.workerSet: - workerOptions.elementsPerWorker = - workerOptions?.elementsPerWorker ?? WorkerConstants.DEFAULT_ELEMENTS_PER_WORKER; workerImplementation = new WorkerSet(workerScript, workerOptions); break; - case WorkerProcessType.staticPool: - workerOptions.poolMaxSize = - workerOptions?.poolMaxSize ?? WorkerConstants.DEFAULT_POOL_MAX_SIZE; - workerImplementation = new WorkerStaticPool(workerScript, workerOptions); + case WorkerProcessType.fixedPool: + workerImplementation = new WorkerFixedPool(workerScript, workerOptions); break; case WorkerProcessType.dynamicPool: - workerOptions.poolMinSize = - workerOptions?.poolMinSize ?? WorkerConstants.DEFAULT_POOL_MIN_SIZE; - workerOptions.poolMaxSize = - workerOptions?.poolMaxSize ?? WorkerConstants.DEFAULT_POOL_MAX_SIZE; workerImplementation = new WorkerDynamicPool(workerScript, workerOptions); break; default: