X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerStaticPool.ts;h=6fc91524173e614e1fb4ff1a7bae586c5e216b22;hb=6c1761d470507ea23d186be61b94ca7375c5144a;hp=cbf46298d67022aeef3a8e35969a4643ed01ce73;hpb=4bfd80fa794b4b2f89427ef9f5944664ce3bdade;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index cbf46298..6fc91524 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -1,8 +1,7 @@ -import { FixedThreadPool, PoolOptions } from 'poolifier'; -import { WorkerData, WorkerStartOptions } from '../types/Worker'; +import { FixedThreadPool } from 'poolifier'; +import type { WorkerData, WorkerOptions } from '../types/Worker'; import Utils from '../utils/Utils'; -import { Worker } from 'worker_threads'; import WorkerAbstract from './WorkerAbstract'; import { WorkerUtils } from './WorkerUtils'; @@ -13,14 +12,17 @@ export default class WorkerStaticPool extends WorkerAbstract { * Create a new `WorkerStaticPool`. * * @param workerScript - * @param numberOfThreads - * @param workerStartOptions - * @param opts + * @param workerOptions */ - constructor(workerScript: string, numberOfThreads: number, workerStartOptions?: WorkerStartOptions, opts?: PoolOptions) { - super(workerScript, workerStartOptions); - opts.exitHandler = opts?.exitHandler ?? WorkerUtils.defaultExitHandler; - this.pool = new FixedThreadPool(numberOfThreads, this.workerScript, opts); + constructor(workerScript: string, workerOptions?: WorkerOptions) { + super(workerScript, workerOptions); + this.workerOptions.poolOptions.exitHandler = + this.workerOptions?.poolOptions?.exitHandler ?? WorkerUtils.defaultExitHandler; + this.pool = new FixedThreadPool( + this.workerOptions.poolMaxSize, + this.workerScript, + this.workerOptions.poolOptions + ); } get size(): number { @@ -58,6 +60,7 @@ export default class WorkerStaticPool extends WorkerAbstract { public async addElement(elementData: WorkerData): Promise { await this.pool.execute(elementData); // Start element sequentially to optimize memory at startup - this.elementStartDelay > 0 && await Utils.sleep(this.elementStartDelay); + this.workerOptions.elementStartDelay > 0 && + (await Utils.sleep(this.workerOptions.elementStartDelay)); } }