X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fworker%2FWorkerFactory.ts;h=fb9a26f1ec2d675c9887ebb96a283a6c252be1f1;hb=60a743910478b70e39dcefa5e1b752ec8a93880e;hp=70bcc3862c4fca8c42a66d7e0f52e7568bfbef80;hpb=6fee1791db82bd4605b180612fe642a7e2c4caa0;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerFactory.ts b/src/worker/WorkerFactory.ts index 70bcc386..fb9a26f1 100644 --- a/src/worker/WorkerFactory.ts +++ b/src/worker/WorkerFactory.ts @@ -1,14 +1,15 @@ -import { Worker, isMainThread } from 'worker_threads'; -import { WorkerData, WorkerOptions, WorkerProcessType } from '../types/Worker'; +import { type Worker, isMainThread } from 'worker_threads'; -import { PoolOptions } from 'poolifier'; -import type WorkerAbstract from './WorkerAbstract'; -import WorkerConstants from './WorkerConstants'; -import WorkerDynamicPool from './WorkerDynamicPool'; -import WorkerSet from './WorkerSet'; -import WorkerStaticPool from './WorkerStaticPool'; +import type { PoolOptions } from 'poolifier'; -export default class WorkerFactory { +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 class WorkerFactory { private constructor() { // This is intentional } @@ -19,7 +20,7 @@ export default class WorkerFactory { workerOptions?: WorkerOptions ): WorkerAbstract | null { if (!isMainThread) { - throw new Error('Trying to get a worker implementation outside the main thread'); + throw new Error('Cannot get a worker implementation outside the main thread'); } workerOptions = workerOptions ?? ({} as WorkerOptions); workerOptions.workerStartDelay = @@ -28,11 +29,8 @@ 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); - console.log('before'); - let workerImplementation: WorkerAbstract = null; - console.log(workerImplementation); + let workerImplementation: WorkerAbstract | null = null; switch (workerProcessType) { case WorkerProcessType.WORKER_SET: workerOptions.elementsPerWorker =