Comment spell fixlet
[poolifier.git] / src / pools / abstract-pool.ts
index e204e1241811c2c0279520706fdce39ad247e881..369e5b90617bab507d97e36331c00a93d6a47c67 100644 (file)
@@ -135,7 +135,7 @@ export abstract class AbstractPool<
       throw new Error(
         'Cannot instantiate a pool without specifying the number of workers'
       )
-    } else if (!Number.isSafeInteger(numberOfWorkers)) {
+    } else if (Number.isSafeInteger(numberOfWorkers) === false) {
       throw new Error(
         'Cannot instantiate a pool with a non integer number of workers'
       )
@@ -226,7 +226,7 @@ export abstract class AbstractPool<
   }
 
   /**
-   * Shut down given worker.
+   * Shutdowns given worker.
    *
    * @param worker A worker within `workers`.
    */
@@ -283,7 +283,7 @@ export abstract class AbstractPool<
   }
 
   /**
-   * Choose a worker for the next task.
+   * Chooses a worker for the next task.
    *
    * The default implementation uses a round robin algorithm to distribute the load.
    *
@@ -294,7 +294,7 @@ export abstract class AbstractPool<
   }
 
   /**
-   * Send a message to the given worker.
+   * Sends a message to the given worker.
    *
    * @param worker The worker which should receive the message.
    * @param message The message.
@@ -305,7 +305,7 @@ export abstract class AbstractPool<
   ): void
 
   /**
-   * Register a listener callback on a given worker.
+   * Registers a listener callback on a given worker.
    *
    * @param worker A worker.
    * @param listener A message listener callback.
@@ -443,10 +443,10 @@ export abstract class AbstractPool<
   }
 
   /**
-   * Updates tasks run time for the given worker.
+   * Updates tasks runtime for the given worker.
    *
    * @param worker Worker which run the task.
-   * @param taskRunTime Worker task run time.
+   * @param taskRunTime Worker task runtime.
    */
   private updateWorkerTasksRunTime (
     worker: Worker,
@@ -457,9 +457,11 @@ export abstract class AbstractPool<
         .requiredStatistics.runTime === true
     ) {
       const tasksUsage = this.workersTasksUsage.get(worker)
-      if (tasksUsage !== undefined && tasksUsage.run !== 0) {
+      if (tasksUsage !== undefined) {
         tasksUsage.runTime += taskRunTime ?? 0
-        tasksUsage.avgRunTime = tasksUsage.runTime / tasksUsage.run
+        if (tasksUsage.run !== 0) {
+          tasksUsage.avgRunTime = tasksUsage.runTime / tasksUsage.run
+        }
         this.workersTasksUsage.set(worker, tasksUsage)
       } else {
         throw new Error(WORKER_NOT_FOUND_TASKS_USAGE_MAP)