Comment spell fixlet
[poolifier.git] / src / pools / pool-internal.ts
index dd71ae71045b555d99b64a24bba516461c77b561..2cf84adbc6bfd28e9d552795cbb3b49bbe8ffee4 100644 (file)
@@ -1,5 +1,5 @@
 import EventEmitter from 'events'
-import type { IWorker } from './abstract-pool'
+import type { AbstractPoolWorker } from './abstract-pool-worker'
 import type { IPool } from './pool'
 
 /**
@@ -10,6 +10,16 @@ export enum PoolType {
   DYNAMIC = 'dynamic'
 }
 
+/**
+ * Tasks usage statistics.
+ */
+export interface TasksUsage {
+  run: number
+  running: number
+  runTime: number
+  avgRunTime: number
+}
+
 /**
  * Internal poolifier pool emitter.
  */
@@ -23,7 +33,7 @@ export class PoolEmitter extends EventEmitter {}
  * @template Response Type of response of execution.
  */
 export interface IPoolInternal<
-  Worker extends IWorker,
+  Worker extends AbstractPoolWorker,
   Data = unknown,
   Response = unknown
 > extends IPool<Data, Response> {
@@ -32,14 +42,6 @@ export interface IPoolInternal<
    */
   readonly workers: Worker[]
 
-  /**
-   * The tasks map.
-   *
-   * - `key`: The `Worker`
-   * - `value`: Number of tasks currently in progress on the worker.
-   */
-  readonly tasks: Map<Worker, number>
-
   /**
    * Emitter on which events can be listened to.
    *
@@ -74,13 +76,37 @@ export interface IPoolInternal<
   readonly numberOfRunningTasks: number
 
   /**
-   * Find a tasks map entry with a free worker based on the number of tasks the worker has applied.
+   * Find a free worker based on the number of tasks the worker has applied.
+   *
+   * If a worker is found with `0` running tasks, it is detected as free and returned.
+   *
+   * If no free worker is found, `false` is returned.
+   *
+   * @returns A free worker if there is one, otherwise `false`.
+   */
+  findFreeWorker(): Worker | false
+
+  /**
+   * Get worker index.
    *
-   * If an entry is found with a worker that has `0` tasks, it is detected as free.
+   * @param worker The worker.
+   * @returns The worker index.
+   */
+  getWorkerIndex(worker: Worker): number
+
+  /**
+   * Get worker running tasks.
    *
-   * If no tasks map entry with a free worker was found, `false` will be returned.
+   * @param worker The worker.
+   * @returns The number of tasks currently running on the worker.
+   */
+  getWorkerRunningTasks(worker: Worker): number | undefined
+
+  /**
+   * Get worker average tasks runtime.
    *
-   * @returns A tasks map entry with a free worker if there was one, otherwise `false`.
+   * @param worker The worker.
+   * @returns The average tasks runtime on the worker.
    */
-  findFreeTasksMapEntry(): [Worker, number] | false
+  getWorkerAverageTasksRunTime(worker: Worker): number | undefined
 }