From: Jérôme Benoit Date: Wed, 23 Aug 2023 22:25:21 +0000 (+0200) Subject: fix: allow to steal tasks more than once at a time X-Git-Tag: v2.6.34~7 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=0741fbebf615c45bb9daa05df0ed4773205e2897;p=poolifier.git fix: allow to steal tasks more than once at a time Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 116fb844..e79aed0b 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -1,7 +1,7 @@ import { MessageChannel } from 'node:worker_threads' import { CircularArray } from '../circular-array' import type { Task } from '../utility-types' -import { DEFAULT_TASK_NAME, once } from '../utils' +import { DEFAULT_TASK_NAME } from '../utils' import { Deque } from '../deque' import { type IWorker, @@ -87,7 +87,7 @@ implements IWorkerNode { public enqueueTask (task: Task): number { const tasksQueueSize = this.tasksQueue.push(task) if (this.onBackPressure != null && this.hasBackPressure()) { - once(this.onBackPressure, this)(this.info.id as number) + this.onBackPressure(this.info.id as number) } return tasksQueueSize } @@ -96,7 +96,7 @@ implements IWorkerNode { public unshiftTask (task: Task): number { const tasksQueueSize = this.tasksQueue.unshift(task) if (this.onBackPressure != null && this.hasBackPressure()) { - once(this.onBackPressure, this)(this.info.id as number) + this.onBackPressure(this.info.id as number) } return tasksQueueSize } @@ -105,7 +105,7 @@ implements IWorkerNode { public dequeueTask (): Task | undefined { const task = this.tasksQueue.shift() if (this.onEmptyQueue != null && this.tasksQueue.size === 0) { - once(this.onEmptyQueue, this)(this.info.id as number) + this.onEmptyQueue(this.info.id as number) } return task } @@ -114,7 +114,7 @@ implements IWorkerNode { public popTask (): Task | undefined { const task = this.tasksQueue.pop() if (this.onEmptyQueue != null && this.tasksQueue.size === 0) { - once(this.onEmptyQueue, this)(this.info.id as number) + this.onEmptyQueue(this.info.id as number) } return task }