Add dynamic worker choice strategy change at runtime
[poolifier.git] / src / pools / pool-internal.ts
index dd71ae71045b555d99b64a24bba516461c77b561..71120110f75bfb48c6e005876b8b7715e53f53fb 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'
 
 /**
@@ -23,7 +23,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> {
@@ -74,13 +74,29 @@ 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 an entry is found with a worker that has `0` tasks, it is detected as free.
+   * If a worker is found with `0` running tasks, it is detected as free and returned.
    *
-   * If no tasks map entry with a free worker was found, `false` will be returned.
+   * If no free worker is found, `false` is returned.
    *
-   * @returns A tasks map entry with a free worker if there was one, otherwise `false`.
+   * @returns A free worker if there is one, otherwise `false`.
    */
-  findFreeTasksMapEntry(): [Worker, number] | false
+  findFreeWorker(): Worker | false
+
+  /**
+   * Get worker index.
+   *
+   * @param worker The worker.
+   * @returns The worker index.
+   */
+  getWorkerIndex(worker: Worker): number
+
+  /**
+   * Get worker running tasks.
+   *
+   * @param worker The worker.
+   * @returns The number of tasks currently running on the worker.
+   */
+  getWorkerRunningTasks(worker: Worker): number | undefined
 }