X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerStaticPool.ts;h=d5d6390c7b2e43ad5175fa46b21c41122879e7ed;hb=1f5df42ad17d09d3a1f53f6618eba325a403d7ad;hp=cf46cfa55f7662f671a5a24635c1f9566feb55f4;hpb=7874b0b1fbf94d34e8c65ed3e669f1c97f74dd1d;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index cf46cfa5..d5d6390c 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -7,19 +7,20 @@ import { WorkerData } from '../types/Worker'; import { WorkerUtils } from './WorkerUtils'; export default class WorkerStaticPool extends WorkerAbstract { - private pool: StaticPool; + private readonly pool: FixedThreadPool; /** * Create a new `WorkerStaticPool`. * - * @param {string} workerScript - * @param {number} numberOfThreads - * @param {number} startWorkerDelay - * @param {PoolOptions} opts + * @param workerScript + * @param numberOfThreads + * @param startWorkerDelay + * @param opts */ constructor(workerScript: string, numberOfThreads: number, startWorkerDelay?: number, opts?: PoolOptions) { super(workerScript, startWorkerDelay); - this.pool = StaticPool.getInstance(numberOfThreads, this.workerScript, opts); + opts.exitHandler = opts?.exitHandler ?? WorkerUtils.defaultExitHandler; + this.pool = new FixedThreadPool(numberOfThreads, this.workerScript, opts); } get size(): number { @@ -32,15 +33,16 @@ export default class WorkerStaticPool extends WorkerAbstract { /** * - * @returns {Promise} + * @returns * @public */ - // eslint-disable-next-line @typescript-eslint/no-empty-function - public async start(): Promise { } + public async start(): Promise { + // This is intentional + } /** * - * @returns {Promise} + * @returns * @public */ public async stop(): Promise { @@ -49,8 +51,8 @@ export default class WorkerStaticPool extends WorkerAbstract { /** * - * @param {T} elementData - * @returns {Promise} + * @param elementData + * @returns * @public */ public async addElement(elementData: T): Promise { @@ -59,19 +61,3 @@ export default class WorkerStaticPool extends WorkerAbstract { await Utils.sleep(this.workerStartDelay); } } - -class StaticPool extends FixedThreadPool { - private static instance: StaticPool; - - private constructor(numberOfThreads: number, workerScript: string, opts?: PoolOptions) { - super(numberOfThreads, workerScript, opts); - } - - public static getInstance(numberOfThreads: number, workerScript: string, opts?: PoolOptions): StaticPool { - if (!StaticPool.instance) { - opts.exitHandler = opts?.exitHandler ?? WorkerUtils.defaultExitHandler; - StaticPool.instance = new StaticPool(numberOfThreads, workerScript, opts); - } - return StaticPool.instance; - } -}