X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fworker%2FWorkerStaticPool.ts;h=ca8c02a0fa613dc1050a18559bd87f82989d16db;hb=63b19acd0a16da3d348fd5aff8d4172e12fba954;hp=c6625d8b609ac55d171e5b7959498242289d90d0;hpb=8434025b7338b3439180ed7c2bed888fc42e04d3;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index c6625d8b..ca8c02a0 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -1,7 +1,8 @@ -import { FixedThreadPool, FixedThreadPoolOptions } from 'poolifier'; +import { FixedThreadPool, PoolOptions } from 'poolifier'; import Constants from '../utils/Constants'; import Utils from '../utils/Utils'; +import { Worker } from 'worker_threads'; import { WorkerData } from '../types/Worker'; import Wrk from './Wrk'; @@ -13,9 +14,9 @@ export default class WorkerStaticPool extends Wrk { * * @param {string} workerScript */ - constructor(workerScript: string, numThreads: number) { + constructor(workerScript: string, numberOfThreads: number) { super(workerScript); - this.pool = StaticPool.getInstance(numThreads, this.workerScript); + this.pool = StaticPool.getInstance(numberOfThreads, this.workerScript); } get size(): number { @@ -34,6 +35,15 @@ export default class WorkerStaticPool extends Wrk { // eslint-disable-next-line @typescript-eslint/no-empty-function public async start(): Promise { } + /** + * + * @return {Promise} + * @public + */ + public async stop(): Promise { + return this.pool.destroy(); + } + /** * * @return {Promise} @@ -49,13 +59,13 @@ export default class WorkerStaticPool extends Wrk { class StaticPool extends FixedThreadPool { private static instance: StaticPool; - private constructor(numThreads: number, workerScript: string, opts?: FixedThreadPoolOptions) { - super(numThreads, workerScript, opts); + private constructor(numberOfThreads: number, workerScript: string, opts?: PoolOptions) { + super(numberOfThreads, workerScript, opts); } - public static getInstance(numThreads: number, workerScript: string): StaticPool { + public static getInstance(numberOfThreads: number, workerScript: string): StaticPool { if (!StaticPool.instance) { - StaticPool.instance = new StaticPool(numThreads, workerScript, + StaticPool.instance = new StaticPool(numberOfThreads, workerScript, { exitHandler: (code) => { if (code !== 0) {