* Maximum number of queued tasks.
*/
readonly maxQueued?: number
+ /**
+ * Number of stolen tasks.
+ */
+ stolen: number
/**
* Number of failed tasks.
*/
/**
* Worker type.
*/
- type: WorkerType
+ readonly type: WorkerType
/**
* Dynamic flag.
*/
/**
* Task function names.
*/
- taskFunctions?: string[]
+ taskFunctionNames?: string[]
}
/**
readonly elu: EventLoopUtilizationMeasurementStatistics
}
+/**
+ * Worker choice strategy data.
+ *
+ * @internal
+ */
+export interface StrategyData {
+ virtualTaskEndTimestamp?: number
+}
+
/**
* Worker interface.
*/
/**
* Registers a listener to the exit event that will only be performed once.
*
- * @param event - `'exit'`.
+ * @param event - The `'exit'` event.
* @param handler - The exit handler.
*/
readonly once: (event: 'exit', handler: ExitHandler<this>) => void
}
+/**
+ * Worker node event detail.
+ *
+ * @internal
+ */
+export interface WorkerNodeEventDetail {
+ workerId: number
+}
+
/**
* Worker node interface.
*
* @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data.
* @internal
*/
-export interface IWorkerNode<Worker extends IWorker, Data = unknown> {
+export interface IWorkerNode<Worker extends IWorker, Data = unknown>
+ extends EventTarget {
/**
* Worker.
*/
* Worker info.
*/
readonly info: WorkerInfo
- /**
- * Message channel (worker_threads only).
- */
- readonly messageChannel?: MessageChannel
/**
* Worker usage statistics.
*/
- usage: WorkerUsage
+ readonly usage: WorkerUsage
/**
- * Tasks queue back pressure size.
- * This is the number of tasks that can be enqueued before the worker node has back pressure.
+ * Worker choice strategy data.
+ * This is used to store data that are specific to the worker choice strategy.
*/
- tasksQueueBackPressureSize: number
+ strategyData?: StrategyData
/**
- * Callback invoked when worker node tasks queue is back pressured.
- *
- * @param workerId - The worker id.
+ * Message channel (worker_threads only).
*/
- onBackPressure?: (workerId: number) => void
+ readonly messageChannel?: MessageChannel
/**
- * Callback invoked when worker node tasks queue is empty.
- *
- * @param workerId - The worker id.
+ * Tasks queue back pressure size.
+ * This is the number of tasks that can be enqueued before the worker node has back pressure.
*/
- onEmptyQueue?: (workerId: number) => void
+ tasksQueueBackPressureSize: number
/**
* Tasks queue size.
*
* @returns The task function worker usage statistics if the task function worker usage statistics are initialized, `undefined` otherwise.
*/
readonly getTaskFunctionWorkerUsage: (name: string) => WorkerUsage | undefined
+ /**
+ * Deletes task function worker usage statistics.
+ *
+ * @param name - The task function name.
+ * @returns `true` if the task function worker usage statistics were deleted, `false` otherwise.
+ */
+ readonly deleteTaskFunctionWorkerUsage: (name: string) => boolean
}