this.checkValidTasksQueueOptions(tasksQueueOptions)
this.opts.tasksQueueOptions =
this.buildTasksQueueOptions(tasksQueueOptions)
- this.setTasksQueueMaxSize(this.opts.tasksQueueOptions.size as number)
+ this.setTasksQueueSize(this.opts.tasksQueueOptions.size as number)
} else if (this.opts.tasksQueueOptions != null) {
delete this.opts.tasksQueueOptions
}
}
- private setTasksQueueMaxSize (size: number): void {
+ private setTasksQueueSize (size: number): void {
for (const workerNode of this.workerNodes) {
workerNode.tasksQueueBackPressureSize = size
}
* @param tasksQueueBackPressureSize - The tasks queue back pressure size.
*/
constructor (worker: Worker, tasksQueueBackPressureSize: number) {
- if (worker == null) {
- throw new TypeError('Cannot construct a worker node without a worker')
- }
- if (tasksQueueBackPressureSize == null) {
- throw new TypeError(
- 'Cannot construct a worker node without a tasks queue back pressure size'
- )
- }
- if (!Number.isSafeInteger(tasksQueueBackPressureSize)) {
- throw new TypeError(
- 'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
- )
- }
+ this.checkWorkerNodeArguments(worker, tasksQueueBackPressureSize)
this.worker = worker
this.info = this.initWorkerInfo(worker)
this.usage = this.initWorkerUsage()
}
}
}
+
+ private checkWorkerNodeArguments (
+ worker: Worker,
+ tasksQueueBackPressureSize: number
+ ): void {
+ if (worker == null) {
+ throw new TypeError('Cannot construct a worker node without a worker')
+ }
+ if (tasksQueueBackPressureSize == null) {
+ throw new TypeError(
+ 'Cannot construct a worker node without a tasks queue back pressure size'
+ )
+ }
+ if (!Number.isSafeInteger(tasksQueueBackPressureSize)) {
+ throw new TypeError(
+ 'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
+ )
+ }
+ if (tasksQueueBackPressureSize <= 0) {
+ throw new RangeError(
+ 'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
+ )
+ }
+ }
}
/**
* Worker type.
*/
- type: WorkerType
+ readonly type: WorkerType
/**
* Dynamic flag.
*/
readonly once: (event: 'exit', handler: ExitHandler<this>) => void
}
+/**
+ * Worker node event callback.
+ *
+ * @param workerId - The worker id.
+ * @internal
+ */
export type WorkerNodeEventCallback = (workerId: number) => void
/**
/**
* Worker usage statistics.
*/
- usage: WorkerUsage
+ readonly usage: WorkerUsage
/**
* Message channel (worker_threads only).
*/
tasksQueueBackPressureSize: number
/**
* Callback invoked when worker node tasks queue is back pressured.
- *
- * @param workerId - The worker id.
*/
onBackPressure?: WorkerNodeEventCallback
/**
* Callback invoked when worker node tasks queue is empty.
- *
- * @param workerId - The worker id.
*/
onEmptyQueue?: WorkerNodeEventCallback
/**
}
/**
- * Performance statistics computation.
+ * Worker task performance statistics computation settings.
*
* @internal
*/
export interface WorkerStatistics {
- runTime: boolean
- elu: boolean
+ /**
+ * Whether the worker computes the task runtime or not.
+ */
+ readonly runTime: boolean
+ /**
+ * Whether the worker computes the task event loop utilization (ELU) or not.
+ */
+ readonly elu: boolean
}
/**
'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
)
)
+ expect(() => new WorkerNode(threadWorker, 0.2)).toThrowError(
+ new TypeError(
+ 'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
+ )
+ )
+ expect(() => new WorkerNode(threadWorker, 0)).toThrowError(
+ new RangeError(
+ 'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
+ )
+ )
+ expect(() => new WorkerNode(threadWorker, -1)).toThrowError(
+ new RangeError(
+ 'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
+ )
+ )
expect(threadWorkerNode).toBeInstanceOf(WorkerNode)
expect(threadWorkerNode.worker).toBe(threadWorker)
expect(threadWorkerNode.info).toStrictEqual({