- public unshiftTask (task: Task<Data>): number {
- const tasksQueueSize = this.tasksQueue.unshift(task)
- if (this.hasBackPressure() && !this.onBackPressureStarted) {
- this.onBackPressureStarted = true
- this.dispatchEvent(
- new CustomEvent<WorkerNodeEventDetail>('backPressure', {
- detail: { workerId: this.info.id as number }
- })
- )
- this.onBackPressureStarted = false
- }
- return tasksQueueSize
- }
-
- /** @inheritdoc */
- public dequeueTask (): Task<Data> | undefined {
- const task = this.tasksQueue.shift()
- if (this.tasksQueue.size === 0 && this.onEmptyQueueCount === 0) {
- this.startOnEmptyQueue().catch(EMPTY_FUNCTION)
- }
- return task
- }
-
- /** @inheritdoc */
- public popTask (): Task<Data> | undefined {
- const task = this.tasksQueue.pop()
- if (this.tasksQueue.size === 0 && this.onEmptyQueueCount === 0) {
- this.startOnEmptyQueue().catch(EMPTY_FUNCTION)
- }
- return task
+ public dequeueTask (bucket?: number): Task<Data> | undefined {
+ return this.tasksQueue.dequeue(bucket)