X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fworker%2FWorkerStaticPool.ts;h=392981237289a78044af6d3a0cd8830eb6888210;hb=c36e3cf0312f553b4b8c2b716da0d55cc87450cf;hp=3eaffff4b48a7c11e4c6c5fa3026b4c9f042b551;hpb=e7aeea18e189dd087c8f951cf77a253e2818ae90;p=e-mobility-charging-stations-simulator.git diff --git a/src/worker/WorkerStaticPool.ts b/src/worker/WorkerStaticPool.ts index 3eaffff4..39298123 100644 --- a/src/worker/WorkerStaticPool.ts +++ b/src/worker/WorkerStaticPool.ts @@ -1,23 +1,20 @@ -import { WorkerData, WorkerOptions } from '../types/Worker'; +import { FixedThreadPool, type PoolEmitter, type PoolInfo } from 'poolifier'; -import { FixedThreadPool } from 'poolifier'; -import Utils from '../utils/Utils'; -import WorkerAbstract from './WorkerAbstract'; -import { WorkerUtils } from './WorkerUtils'; +import { WorkerAbstract } from './WorkerAbstract'; +import type { WorkerData, WorkerOptions } from './WorkerTypes'; +import { sleep } from './WorkerUtils'; -export default class WorkerStaticPool extends WorkerAbstract { +export class WorkerStaticPool extends WorkerAbstract { private readonly pool: FixedThreadPool; /** - * Create a new `WorkerStaticPool`. + * Creates a new `WorkerStaticPool`. * - * @param workerScript - * @param workerOptions + * @param workerScript - + * @param workerOptions - */ 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, @@ -25,42 +22,36 @@ export default class WorkerStaticPool extends WorkerAbstract { ); } + get info(): PoolInfo { + return this.pool.info; + } + get size(): number { - return this.pool.workers.length; + return this.pool.info.workerNodes; } - get maxElementsPerWorker(): number | null { - return null; + get maxElementsPerWorker(): number | undefined { + return undefined; } - /** - * - * @returns - * @public - */ + get emitter(): PoolEmitter | undefined { + return this.pool?.emitter; + } + + /** @inheritDoc */ public async start(): Promise { // This is intentional } - /** - * - * @returns - * @public - */ + /** @inheritDoc */ public async stop(): Promise { return this.pool.destroy(); } - /** - * - * @param elementData - * @returns - * @public - */ + /** @inheritDoc */ public async addElement(elementData: WorkerData): Promise { await this.pool.execute(elementData); // Start element sequentially to optimize memory at startup - this.workerOptions.elementStartDelay > 0 && - (await Utils.sleep(this.workerOptions.elementStartDelay)); + this.workerOptions.elementStartDelay > 0 && (await sleep(this.workerOptions.elementStartDelay)); } }