X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fworker%2FWorkerStaticPool.ts;h=2ec049e15514d356fbb0b787c43f48e3efd9d1ff;hb=29405d4fc27d01f8186482c0826b290152d027fe;hp=3eaffff4b48a7c11e4c6c5fa3026b4c9f042b551;hpb=e7aeea18e189dd087c8f951cf77a253e2818ae90;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index 3eaffff4..2ec049e1 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -1,9 +1,11 @@ -import { WorkerData, WorkerOptions } from '../types/Worker'; +import type { Worker } from 'worker_threads'; + +import { type ErrorHandler, type ExitHandler, FixedThreadPool } from 'poolifier'; -import { FixedThreadPool } from 'poolifier'; -import Utils from '../utils/Utils'; import WorkerAbstract from './WorkerAbstract'; import { WorkerUtils } from './WorkerUtils'; +import type { WorkerData, WorkerOptions } from '../types/Worker'; +import Utils from '../utils/Utils'; export default class WorkerStaticPool extends WorkerAbstract { private readonly pool: FixedThreadPool; @@ -11,13 +13,18 @@ export default class WorkerStaticPool extends WorkerAbstract { /** * Create a new `WorkerStaticPool`. * - * @param workerScript - * @param workerOptions + * @param workerScript - + * @param workerOptions - */ constructor(workerScript: string, workerOptions?: WorkerOptions) { super(workerScript, workerOptions); - this.workerOptions.poolOptions.exitHandler = - this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler; + this.workerOptions.poolOptions.errorHandler = ( + this.workerOptions?.poolOptions?.errorHandler ?? WorkerUtils.defaultErrorHandler + ).bind(this) as ErrorHandler; + this.workerOptions.poolOptions.exitHandler = ( + this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler + ).bind(this) as ExitHandler; + this.workerOptions.poolOptions.messageHandler.bind(this); this.pool = new FixedThreadPool( this.workerOptions.poolMaxSize, this.workerScript, @@ -29,8 +36,8 @@ export default class WorkerStaticPool extends WorkerAbstract { return this.pool.workers.length; } - get maxElementsPerWorker(): number | null { - return null; + get maxElementsPerWorker(): number | undefined { + return undefined; } /** @@ -53,7 +60,7 @@ export default class WorkerStaticPool extends WorkerAbstract { /** * - * @param elementData + * @param elementData - * @returns * @public */