X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker-node.ts;h=a2878d8980e4c300a7dc0712c7fbbbe971868f27;hb=85bbc7ab16c9f69a5dd358b71e3e6d4204dfd630;hp=308215176edb515851c2349ba550d3cc50e2611b;hpb=e9ed6eeed0f1c96d89c1506ee342b3000a95b4ba;p=poolifier.git diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 30821517..a2878d89 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -1,9 +1,16 @@ -import { MessageChannel } from 'node:worker_threads' import { EventEmitter } from 'node:events' +import { MessageChannel } from 'node:worker_threads' + import { CircularArray } from '../circular-array.js' +import { Deque } from '../deque.js' import type { Task } from '../utility-types.js' import { DEFAULT_TASK_NAME } from '../utils.js' -import { Deque } from '../deque.js' +import { + checkWorkerNodeArguments, + createWorker, + getWorkerId, + getWorkerType +} from './utils.js' import { type EventHandler, type IWorker, @@ -15,12 +22,6 @@ import { WorkerTypes, type WorkerUsage } from './worker.js' -import { - checkWorkerNodeArguments, - createWorker, - getWorkerId, - getWorkerType -} from './utils.js' /** * Worker node. @@ -137,6 +138,7 @@ export class WorkerNode this.removeAllListeners() switch (this.info.type) { case WorkerTypes.thread: + this.worker.unref?.() await this.worker.terminate?.() break case WorkerTypes.cluster: @@ -167,21 +169,21 @@ export class WorkerNode /** @inheritdoc */ public getTaskFunctionWorkerUsage (name: string): WorkerUsage | undefined { - if (!Array.isArray(this.info.taskFunctionNames)) { + if (!Array.isArray(this.info.taskFunctionsProperties)) { throw new Error( - `Cannot get task function worker usage for task function name '${name}' when task function names list is not yet defined` + `Cannot get task function worker usage for task function name '${name}' when task function properties list is not yet defined` ) } if ( - Array.isArray(this.info.taskFunctionNames) && - this.info.taskFunctionNames.length < 3 + Array.isArray(this.info.taskFunctionsProperties) && + this.info.taskFunctionsProperties.length < 3 ) { throw new Error( - `Cannot get task function worker usage for task function name '${name}' when task function names list has less than 3 elements` + `Cannot get task function worker usage for task function name '${name}' when task function properties list has less than 3 elements` ) } if (name === DEFAULT_TASK_NAME) { - name = this.info.taskFunctionNames[1] + name = this.info.taskFunctionsProperties[1].name } if (!this.taskFunctionsUsage.has(name)) { this.taskFunctionsUsage.set(name, this.initTaskFunctionWorkerUsage(name)) @@ -260,7 +262,7 @@ export class WorkerNode if ( (task.name === DEFAULT_TASK_NAME && // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - name === this.info.taskFunctionNames![1]) || + name === this.info.taskFunctionsProperties![1].name) || (task.name !== DEFAULT_TASK_NAME && name === task.name) ) { ++taskFunctionQueueSize