X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerFactory.ts;h=76da7a20fc453d561218814be001e53a43a7c546;hb=6114e6f11b3fb12439d464e142fdf93866982b6c;hp=55cb1da7a55fe2cf50d5b282d1ba703aa8f54c4a;hpb=2f70f96f076d2689ff4f392dd32f8499cb2e4100;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index 55cb1da7..76da7a20 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -1,5 +1,5 @@ import { Worker, isMainThread } from 'worker_threads'; -import { WorkerOptions, WorkerProcessType } from '../types/Worker'; +import { WorkerData, WorkerOptions, WorkerProcessType } from '../types/Worker'; import Constants from '../utils/Constants'; import { PoolOptions } from 'poolifier'; @@ -9,12 +9,11 @@ import WorkerSet from './WorkerSet'; import WorkerStaticPool from './WorkerStaticPool'; export default class WorkerFactory { - // eslint-disable-next-line @typescript-eslint/no-empty-function private constructor() { // This is intentional } - public static getWorkerImplementation(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): WorkerAbstract | null { + public static getWorkerImplementation(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): WorkerAbstract | null { if (!isMainThread) { throw new Error('Trying to get a worker implementation outside the main thread'); } @@ -22,20 +21,20 @@ export default class WorkerFactory { options.startDelay = options?.startDelay ?? Constants.WORKER_START_DELAY; options.poolOptions = options?.poolOptions ?? {} as PoolOptions; options?.messageHandler && (options.poolOptions.messageHandler = options.messageHandler); - let workerImplementation: WorkerAbstract = null; + let workerImplementation: WorkerAbstract = null; switch (workerProcessType) { case WorkerProcessType.WORKER_SET: options.elementsPerWorker = options.elementsPerWorker ?? Constants.DEFAULT_CHARGING_STATIONS_PER_WORKER; - workerImplementation = new WorkerSet(workerScript, options.elementsPerWorker, options.startDelay, options); + workerImplementation = new WorkerSet(workerScript, options.elementsPerWorker, options.startDelay, options); break; case WorkerProcessType.STATIC_POOL: options.poolMaxSize = options.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE; - workerImplementation = new WorkerStaticPool(workerScript, options.poolMaxSize, options.startDelay, options.poolOptions); + workerImplementation = new WorkerStaticPool(workerScript, options.poolMaxSize, options.startDelay, options.poolOptions); break; case WorkerProcessType.DYNAMIC_POOL: options.poolMinSize = options.poolMinSize ?? Constants.DEFAULT_WORKER_POOL_MIN_SIZE; options.poolMaxSize = options.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE; - workerImplementation = new WorkerDynamicPool(workerScript, options.poolMinSize, options.poolMaxSize, options.startDelay, options.poolOptions); + workerImplementation = new WorkerDynamicPool(workerScript, options.poolMinSize, options.poolMaxSize, options.startDelay, options.poolOptions); break; default: throw new Error(`Worker implementation type '${workerProcessType}' not found`);