return 0
}
return this.workerNodes.reduce(
- (accumulator, workerNode) => accumulator + workerNode.tasksQueue.size(),
+ (accumulator, workerNode) => accumulator + workerNode.tasksQueue.size,
0
)
}
}
private tasksQueueSize (workerNodeKey: number): number {
- return this.workerNodes[workerNodeKey].tasksQueue.size()
+ return this.workerNodes[workerNodeKey].tasksQueue.size
}
private flushTasksQueue (workerNodeKey: number): void {
private head: number
private tail: number
- constructor () {
+ public constructor () {
this.items = {}
this.head = 0
this.tail = 0
}
- enqueue (item: T): number {
+ public get size (): number {
+ return this.tail - this.head
+ }
+
+ public enqueue (item: T): number {
this.items[this.tail] = item
this.tail++
- return this.size()
+ return this.size
}
- dequeue (): T | undefined {
- if (this.size() <= 0) return undefined
+ public dequeue (): T | undefined {
+ if (this.size <= 0) return undefined
const item = this.items[this.head]
// eslint-disable-next-line @typescript-eslint/no-dynamic-delete
delete this.items[this.head]
}
return item
}
-
- size (): number {
- return this.tail - this.head
- }
}
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksQueue).toBeDefined()
expect(workerNode.tasksQueue).toBeInstanceOf(Queue)
- expect(workerNode.tasksQueue.size()).toBe(0)
+ expect(workerNode.tasksQueue.size).toBe(0)
}
await pool.destroy()
})
queuePool.opts.tasksQueueOptions.concurrency
)
expect(workerNode.tasksUsage.run).toBe(0)
- expect(workerNode.tasksQueue.size()).toBeGreaterThan(0)
+ expect(workerNode.tasksQueue.size).toBeGreaterThan(0)
}
expect(queuePool.numberOfRunningTasks).toBe(numberOfWorkers)
expect(queuePool.numberOfQueuedTasks).toBe(
for (const workerNode of queuePool.workerNodes) {
expect(workerNode.tasksUsage.running).toBe(0)
expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksQueue.size()).toBe(0)
+ expect(workerNode.tasksQueue.size).toBe(0)
}
promises.clear()
})
queuePool.opts.tasksQueueOptions.concurrency
)
expect(workerNode.tasksUsage.run).toBe(0)
- expect(workerNode.tasksQueue.size()).toBeGreaterThan(0)
+ expect(workerNode.tasksQueue.size).toBeGreaterThan(0)
}
expect(queuePool.numberOfRunningTasks).toBe(numberOfThreads)
expect(queuePool.numberOfQueuedTasks).toBe(
for (const workerNode of queuePool.workerNodes) {
expect(workerNode.tasksUsage.running).toBe(0)
expect(workerNode.tasksUsage.run).toBeGreaterThan(0)
- expect(workerNode.tasksQueue.size()).toBe(0)
+ expect(workerNode.tasksQueue.size).toBe(0)
}
promises.clear()
})