X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fworker%2FWorkerStaticPool.ts;h=7a304b707d62b0083c98ce82795921f5ff92072c;hb=2bbddc367e37d0d163ee0e22f63c7093bb3aa0cd;hp=c78768e01360a788f131029025433ee8590a5f9b;hpb=322c9192eaa7142da1bf475cc2c6588ca72d922c;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index c78768e0..7a304b70 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -14,17 +14,18 @@ export default class WorkerStaticPool extends WorkerAbstract { * @param {string} workerScript * @param {number} numberOfThreads * @param {number} startWorkerDelay + * @param {PoolOptions} opts */ - constructor(workerScript: string, numberOfThreads: number, startWorkerDelay?: number) { + constructor(workerScript: string, numberOfThreads: number, startWorkerDelay?: number, opts?: PoolOptions) { super(workerScript, startWorkerDelay); - this.pool = StaticPool.getInstance(numberOfThreads, this.workerScript); + this.pool = StaticPool.getInstance(numberOfThreads, this.workerScript, opts); } get size(): number { return this.pool.workers.length; } - get maxElementsPerWorker(): number { + get maxElementsPerWorker(): number | null { return null; } @@ -47,7 +48,7 @@ export default class WorkerStaticPool extends WorkerAbstract { /** * - * @param elementData + * @param {T} elementData * @returns {Promise} * @public */ @@ -65,17 +66,14 @@ class StaticPool extends FixedThreadPool { super(numberOfThreads, workerScript, opts); } - public static getInstance(numberOfThreads: number, workerScript: string): StaticPool { + public static getInstance(numberOfThreads: number, workerScript: string, opts?: PoolOptions): StaticPool { if (!StaticPool.instance) { - StaticPool.instance = new StaticPool(numberOfThreads, workerScript, - { - exitHandler: (code) => { - if (code !== 0) { - console.error(`Worker stopped with exit code ${code}`); - } - } + opts.exitHandler = opts?.exitHandler ?? ((code) => { + if (code !== 0) { + console.error(`Worker stopped with exit code ${code}`); } - ); + }); + StaticPool.instance = new StaticPool(numberOfThreads, workerScript, opts); } return StaticPool.instance; }