X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fabstract-pool.ts;h=66b1ea1da3f3ba47d93cda9c94d2b2a19cc63ac3;hb=bf90656cacf88d2cfdd5b3262086ba55b2ff9818;hp=095a4f7b99840ff1c0ff9074d6cd66dca2efa1d0;hpb=97a2abc3c559695c4fae99c48d1a2dc636275ccb;p=poolifier.git diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 095a4f7b..66b1ea1d 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -146,7 +146,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) @@ -177,16 +177,15 @@ export abstract class AbstractPool< protected internalGetBusyStatus (): 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} */