Apply dependencies update (#482)
[poolifier.git] / src / pools / pool-internal.ts
index 911e761df157a07f54ac1300328c82548cc6d9d6..dd71ae71045b555d99b64a24bba516461c77b561 100644 (file)
@@ -2,6 +2,14 @@ import EventEmitter from 'events'
 import type { IWorker } from './abstract-pool'
 import type { IPool } from './pool'
 
+/**
+ * Pool types.
+ */
+export enum PoolType {
+  FIXED = 'fixed',
+  DYNAMIC = 'dynamic'
+}
+
 /**
  * Internal poolifier pool emitter.
  */
@@ -39,17 +47,40 @@ export interface IPoolInternal<
    *
    * - `'busy'`
    */
-  readonly emitter: PoolEmitter
+  readonly emitter?: PoolEmitter
 
   /**
-   * Whether the pool is dynamic or not.
+   * Pool type.
    *
-   * If it is dynamic, it provides the `max` property.
+   * If it is `'dynamic'`, it provides the `max` property.
    */
-  readonly dynamic: boolean
+  readonly type: PoolType
 
   /**
    * Maximum number of workers that can be created by this pool.
    */
   readonly max?: number
+
+  /**
+   * Whether the pool is busy or not.
+   *
+   * The pool busyness boolean status.
+   */
+  readonly busy: boolean
+
+  /**
+   * Number of tasks currently concurrently running.
+   */
+  readonly numberOfRunningTasks: number
+
+  /**
+   * Find a tasks map entry with 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 no tasks map entry with a free worker was found, `false` will be returned.
+   *
+   * @returns A tasks map entry with a free worker if there was one, otherwise `false`.
+   */
+  findFreeTasksMapEntry(): [Worker, number] | false
 }