X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fabstract-pool.ts;h=1e61071c42382e1ccb9d546cb0a035ac6196afe3;hb=c2ade475e1b3b24aa2a1757b6d97a26063ec708c;hp=095a4f7b99840ff1c0ff9074d6cd66dca2efa1d0;hpb=97a2abc3c559695c4fae99c48d1a2dc636275ccb;p=poolifier.git diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 095a4f7b..1e61071c 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -73,6 +73,12 @@ export abstract class AbstractPool< this.checkNumberOfWorkers(this.numberOfWorkers) this.checkFilePath(this.filePath) this.checkPoolOptions(this.opts) + + this.chooseWorker.bind(this) + this.internalExecute.bind(this) + this.checkAndEmitBusy.bind(this) + this.sendToWorker.bind(this) + this.setupHook() for (let i = 1; i <= this.numberOfWorkers; i++) { @@ -137,8 +143,10 @@ export abstract class AbstractPool< /** {@inheritDoc} */ public abstract get type (): PoolType - /** {@inheritDoc} */ - public get numberOfRunningTasks (): number { + /** + * Number of tasks concurrently running. + */ + private get numberOfRunningTasks (): number { return this.promiseResponseMap.size } @@ -146,7 +154,7 @@ export abstract class AbstractPool< * Gets the given worker key. * * @param worker - The worker. - * @returns The worker key. + * @returns The worker key if the worker is found in the pool, `-1` otherwise. */ private getWorkerKey (worker: Worker): number { return this.workers.findIndex(workerItem => workerItem.worker === worker) @@ -171,22 +179,24 @@ export abstract class AbstractPool< ) } + /** {@inheritDoc} */ + public abstract get full (): boolean + /** {@inheritDoc} */ public abstract get busy (): boolean - protected internalGetBusyStatus (): boolean { + protected internalBusy (): boolean { return ( this.numberOfRunningTasks >= this.numberOfWorkers && - this.findFreeWorkerKey() === false + this.findFreeWorkerKey() === -1 ) } /** {@inheritDoc} */ - public findFreeWorkerKey (): number | false { - const freeWorkerKey = this.workers.findIndex(workerItem => { + public findFreeWorkerKey (): number { + return this.workers.findIndex(workerItem => { return workerItem.tasksUsage.running === 0 }) - return freeWorkerKey !== -1 ? freeWorkerKey : false } /** {@inheritDoc} */ @@ -262,7 +272,10 @@ export abstract class AbstractPool< } if (this.workerChoiceStrategyContext.getRequiredStatistics().runTime) { workerTasksUsage.runTime += message.taskRunTime ?? 0 - if (workerTasksUsage.run !== 0) { + if ( + this.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime && + workerTasksUsage.run !== 0 + ) { workerTasksUsage.avgRunTime = workerTasksUsage.runTime / workerTasksUsage.run }