From 0741fbebf615c45bb9daa05df0ed4773205e2897 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 24 Aug 2023 00:25:21 +0200 Subject: [PATCH] fix: allow to steal tasks more than once at a time MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/worker-node.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 } -- 2.34.1