chore: v3.1.25
[poolifier.git] / src / pools / pool.ts
index 3aa9feb70b04d8ea3b321777dd053d9823d994b0..1fa5b0f5e333a18c706d24705cc297b27d47d2ba 100644 (file)
@@ -1,7 +1,12 @@
-import type { TransferListItem, WorkerOptions } from 'node:worker_threads'
-import type { EventEmitterAsyncResource } from 'node:events'
 import type { ClusterSettings } from 'node:cluster'
+import type { EventEmitterAsyncResource } from 'node:events'
+import type { TransferListItem, WorkerOptions } from 'node:worker_threads'
+
 import type { TaskFunction } from '../worker/task-functions.js'
+import type {
+  WorkerChoiceStrategy,
+  WorkerChoiceStrategyOptions
+} from './selection-strategies/selection-strategies-types.js'
 import type {
   ErrorHandler,
   ExitHandler,
@@ -11,10 +16,6 @@ import type {
   OnlineHandler,
   WorkerType
 } from './worker.js'
-import type {
-  WorkerChoiceStrategy,
-  WorkerChoiceStrategyOptions
-} from './selection-strategies/selection-strategies-types.js'
 
 /**
  * Enumeration of pool types.
@@ -42,6 +43,7 @@ export const PoolEvents = Object.freeze({
   ready: 'ready',
   busy: 'busy',
   full: 'full',
+  empty: 'empty',
   destroy: 'destroy',
   error: 'error',
   taskError: 'taskError',
@@ -63,6 +65,7 @@ export interface PoolInfo {
   readonly started: boolean
   readonly ready: boolean
   readonly strategy: WorkerChoiceStrategy
+  readonly strategyRetries: number
   readonly minSize: number
   readonly maxSize: number
   /** Pool utilization. */
@@ -241,14 +244,15 @@ export interface IPool<
    */
   readonly workerNodes: Array<IWorkerNode<Worker, Data>>
   /**
-   * Event emitter integrated with async resource on which events can be listened to.
+   * Pool event emitter integrated with async resource.
    * The async tracking tooling identifier is `poolifier:<PoolType>-<WorkerType>-pool`.
    *
    * Events that can currently be listened to:
    *
-   * - `'ready'`: Emitted when the number of workers created in the pool has reached the minimum size expected and are ready.
+   * - `'ready'`: Emitted when the number of workers created in the pool has reached the minimum size expected and are ready. If the pool is dynamic with a minimum number of workers is set to zero, this event is emitted when at least one dynamic worker is ready.
    * - `'busy'`: Emitted when the number of workers created in the pool has reached the maximum size expected and are executing concurrently their tasks quota.
    * - `'full'`: Emitted when the pool is dynamic and the number of workers created has reached the maximum size expected.
+   * - `'empty'`: Emitted when the pool is dynamic with a minimum number of workers set to zero and the number of workers has reached the minimum size expected.
    * - `'destroy'`: Emitted when the pool is destroyed.
    * - `'error'`: Emitted when an uncaught error occurs.
    * - `'taskError'`: Emitted when an error occurs while executing a task.