} from './pools/pool'
export { WorkerTypes } from './pools/worker'
export type {
- BackPressureCallback,
- EmptyQueueCallback,
ErrorHandler,
EventLoopUtilizationMeasurementStatistics,
ExitHandler,
OnlineHandler,
TaskStatistics,
WorkerInfo,
+ WorkerNodeEventCallback,
WorkerType,
WorkerUsage
} from './pools/worker'
* 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.
- * - `'busy'`: Emitted when the number of workers created in the pool has reached the maximum size expected and are executing at least one task.
+ * - `'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.
* - `'destroy'`: Emitted when the pool is destroyed.
* - `'error'`: Emitted when an uncaught error occurs.
} from '../utils'
import { Deque } from '../deque'
import {
- type BackPressureCallback,
- type EmptyQueueCallback,
type IWorker,
type IWorkerNode,
type WorkerInfo,
+ type WorkerNodeEventCallback,
type WorkerType,
WorkerTypes,
type WorkerUsage
/** @inheritdoc */
public tasksQueueBackPressureSize: number
/** @inheritdoc */
- public onBackPressure?: BackPressureCallback
+ public onBackPressure?: WorkerNodeEventCallback
/** @inheritdoc */
- public onEmptyQueue?: EmptyQueueCallback
+ public onEmptyQueue?: WorkerNodeEventCallback
private readonly tasksQueue: Deque<Task<Data>>
private onEmptyQueueCount: number
private readonly taskFunctionsUsage: Map<string, WorkerUsage>
this.onEmptyQueueCount = 0
return
}
- (this.onEmptyQueue as EmptyQueueCallback)(this.info.id as number)
+ (this.onEmptyQueue as WorkerNodeEventCallback)(this.info.id as number)
++this.onEmptyQueueCount
await sleep(exponentialDelay(this.onEmptyQueueCount))
await this.startOnEmptyQueue()
readonly once: (event: 'exit', handler: ExitHandler<this>) => void
}
-export type EmptyQueueCallback = (workerId: number) => void
-export type BackPressureCallback = EmptyQueueCallback
+export type WorkerNodeEventCallback = (workerId: number) => void
/**
* Worker node interface.
*
* @param workerId - The worker id.
*/
- onBackPressure?: EmptyQueueCallback
+ onBackPressure?: WorkerNodeEventCallback
/**
* Callback invoked when worker node tasks queue is empty.
*
* @param workerId - The worker id.
*/
- onEmptyQueue?: BackPressureCallback
+ onEmptyQueue?: WorkerNodeEventCallback
/**
* Tasks queue size.
*