Apply dependencies update (#482)
[poolifier.git] / src / pools / pool-internal.ts
index d641fcf9d9fec246ee26a92a67a78d348b3dacf3..dd71ae71045b555d99b64a24bba516461c77b561 100644 (file)
@@ -1,8 +1,15 @@
 import EventEmitter from 'events'
-import type { MessageValue } from '../utility-types'
 import type { IWorker } from './abstract-pool'
 import type { IPool } from './pool'
 
+/**
+ * Pool types.
+ */
+export enum PoolType {
+  FIXED = 'fixed',
+  DYNAMIC = 'dynamic'
+}
+
 /**
  * Internal poolifier pool emitter.
  */
@@ -38,16 +45,16 @@ export interface IPoolInternal<
    *
    * Events that can currently be listened to:
    *
-   * - `'FullPool'`
+   * - `'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.
@@ -55,27 +62,25 @@ export interface IPoolInternal<
   readonly max?: number
 
   /**
-   * Creates a new worker for this pool and sets it up completely.
+   * Whether the pool is busy or not.
    *
-   * @returns New, completely set up worker.
+   * The pool busyness boolean status.
    */
-  createAndSetupWorker(): Worker
+  readonly busy: boolean
 
   /**
-   * Shut down given worker.
-   *
-   * @param worker A worker within `workers`.
+   * Number of tasks currently concurrently running.
    */
-  destroyWorker(worker: Worker): void | Promise<void>
+  readonly numberOfRunningTasks: number
 
   /**
-   * Register a listener callback on a given worker.
+   * 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.
    *
-   * @param worker A worker.
-   * @param listener A message listener callback.
+   * @returns A tasks map entry with a free worker if there was one, otherwise `false`.
    */
-  registerWorkerMessageListener<Message extends Data | Response>(
-    worker: Worker,
-    listener: (message: MessageValue<Message>) => void
-  ): void
+  findFreeTasksMapEntry(): [Worker, number] | false
 }