X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerDynamicPool.ts;h=45bc6a7a9406adedbdb683a92773ecda0ceb335e;hb=3e8d029bbd0a072ae80c45e9a50770de3218cbc1;hp=af8b7e2add2e882195baa8983fc7a2e4465d15c4;hpb=8baf3f8f3e3330c90cbd3474b6f5c7d589be17ff;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerDynamicPool.ts b/src/worker/WorkerDynamicPool.ts index af8b7e2a..45bc6a7a 100644 --- a/src/worker/WorkerDynamicPool.ts +++ b/src/worker/WorkerDynamicPool.ts @@ -1,29 +1,20 @@ -import type { Worker } from 'node:worker_threads'; - -import { DynamicThreadPool, type ErrorHandler, type ExitHandler } from 'poolifier'; +import { DynamicThreadPool, type PoolEmitter, type PoolInfo } from 'poolifier'; import { WorkerAbstract } from './WorkerAbstract'; import type { WorkerData, WorkerOptions } from './WorkerTypes'; -import { defaultErrorHandler, defaultExitHandler, sleep } from './WorkerUtils'; +import { sleep } from './WorkerUtils'; export class WorkerDynamicPool extends WorkerAbstract { private readonly pool: DynamicThreadPool; /** - * Create a new `WorkerDynamicPool`. + * Creates a new `WorkerDynamicPool`. * * @param workerScript - * @param workerOptions - */ constructor(workerScript: string, workerOptions?: WorkerOptions) { super(workerScript, workerOptions); - this.workerOptions.poolOptions.errorHandler = ( - this.workerOptions?.poolOptions?.errorHandler ?? defaultErrorHandler - ).bind(this) as ErrorHandler; - this.workerOptions.poolOptions.exitHandler = ( - this.workerOptions?.poolOptions?.exitHandler ?? defaultExitHandler - ).bind(this) as ExitHandler; - this.workerOptions.poolOptions.messageHandler.bind(this); this.pool = new DynamicThreadPool( this.workerOptions.poolMinSize, this.workerOptions.poolMaxSize, @@ -32,14 +23,22 @@ export class WorkerDynamicPool extends WorkerAbstract { ); } + get info(): PoolInfo { + return this.pool.info; + } + get size(): number { - return this.pool.workerNodes.length; + return this.pool.info.workerNodes; } get maxElementsPerWorker(): number | undefined { return undefined; } + get emitter(): PoolEmitter | undefined { + return this.pool?.emitter; + } + /** @inheritDoc */ public async start(): Promise { // This is intentional