fix: refine type definition for transferList
[poolifier.git] / src / pools / pool.ts
index cda63d881f0bab742cf0412cfa266714fdefeb27..bcf7d9385035b938ac3c0ed9bdb24dda6382e0a1 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,15 +16,14 @@ import type {
   OnlineHandler,
   WorkerType
 } from './worker.js'
-import type {
-  WorkerChoiceStrategy,
-  WorkerChoiceStrategyOptions
-} from './selection-strategies/selection-strategies-types.js'
 
 /**
  * Enumeration of pool types.
  */
-export const PoolTypes = Object.freeze({
+export const PoolTypes: Readonly<{
+  fixed: 'fixed'
+  dynamic: 'dynamic'
+}> = Object.freeze({
   /**
    * Fixed pool type.
    */
@@ -38,7 +42,16 @@ export type PoolType = keyof typeof PoolTypes
 /**
  * Enumeration of pool events.
  */
-export const PoolEvents = Object.freeze({
+export const PoolEvents: Readonly<{
+  ready: 'ready'
+  busy: 'busy'
+  full: 'full'
+  empty: 'empty'
+  destroy: 'destroy'
+  error: 'error'
+  taskError: 'taskError'
+  backPressure: 'backPressure'
+}> = Object.freeze({
   ready: 'ready',
   busy: 'busy',
   full: 'full',
@@ -64,6 +77,7 @@ export interface PoolInfo {
   readonly started: boolean
   readonly ready: boolean
   readonly strategy: WorkerChoiceStrategy
+  readonly strategyRetries: number
   readonly minSize: number
   readonly maxSize: number
   /** Pool utilization. */
@@ -242,7 +256,7 @@ 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:
@@ -268,7 +282,7 @@ export interface IPool<
   readonly execute: (
     data?: Data,
     name?: string,
-    transferList?: TransferListItem[]
+    transferList?: readonly TransferListItem[]
   ) => Promise<Response>
   /**
    * Starts the minimum number of workers in this pool.