refactor: align findFreeWorkerKey() return type with findIndex()
[poolifier.git] / src / pools / abstract-pool.ts
index 095a4f7b99840ff1c0ff9074d6cd66dca2efa1d0..66b1ea1da3f3ba47d93cda9c94d2b2a19cc63ac3 100644 (file)
@@ -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} */