X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerFactory.ts;h=833c939f1767e832b021f152a5d2725caf221f72;hb=5a6bab3beacdd3b357e7e624c37e4e414d493f6f;hp=608e879859b9662cb093241aec71fccd7d0a9ea1;hpb=cbaa683986beae870b1a98570b39dbfb030b52db;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index 608e8798..833c939f 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -1,41 +1,42 @@ -import { isMainThread } from 'node:worker_threads'; +import { isMainThread } from 'node:worker_threads' -import type { WorkerAbstract } from './WorkerAbstract'; -import { DEFAULT_WORKER_OPTIONS } from './WorkerConstants'; -import { WorkerDynamicPool } from './WorkerDynamicPool'; -import { WorkerFixedPool } from './WorkerFixedPool'; -import { WorkerSet } from './WorkerSet'; -import { type WorkerData, type WorkerOptions, WorkerProcessType } from './WorkerTypes'; +import type { WorkerAbstract } from './WorkerAbstract.js' +import { DEFAULT_WORKER_OPTIONS } from './WorkerConstants.js' +import { WorkerDynamicPool } from './WorkerDynamicPool.js' +import { WorkerFixedPool } from './WorkerFixedPool.js' +import { WorkerSet } from './WorkerSet.js' +import { type WorkerData, type WorkerOptions, WorkerProcessType } from './WorkerTypes.js' +// eslint-disable-next-line @typescript-eslint/no-extraneous-class export class WorkerFactory { - private constructor() { + private constructor () { // This is intentional } public static getWorkerImplementation( workerScript: string, workerProcessType: WorkerProcessType, - workerOptions?: WorkerOptions, + workerOptions?: WorkerOptions ): WorkerAbstract | undefined { if (!isMainThread) { - throw new Error('Cannot get a worker implementation outside the main thread'); + throw new Error('Cannot get a worker implementation outside the main thread') } - workerOptions = { ...DEFAULT_WORKER_OPTIONS, ...workerOptions }; - let workerImplementation: WorkerAbstract; + workerOptions = { ...DEFAULT_WORKER_OPTIONS, ...workerOptions } + let workerImplementation: WorkerAbstract switch (workerProcessType) { case WorkerProcessType.workerSet: - workerImplementation = new WorkerSet(workerScript, workerOptions); - break; + workerImplementation = new WorkerSet(workerScript, workerOptions) + break case WorkerProcessType.fixedPool: - workerImplementation = new WorkerFixedPool(workerScript, workerOptions); - break; + workerImplementation = new WorkerFixedPool(workerScript, workerOptions) + break case WorkerProcessType.dynamicPool: - workerImplementation = new WorkerDynamicPool(workerScript, workerOptions); - break; + workerImplementation = new WorkerDynamicPool(workerScript, workerOptions) + break default: // eslint-disable-next-line @typescript-eslint/restrict-template-expressions - throw new Error(`Worker implementation type '${workerProcessType}' not found`); + throw new Error(`Worker implementation type '${workerProcessType}' not found`) } - return workerImplementation; + return workerImplementation } }