X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fworker-node.ts;h=4349ed72471b3614e227ab4d374df7f0aba17186;hb=c4e7e9d1e0c33a8318b60f2165269edcf3352a90;hp=3b69d3854e07015aa0019ee84f164b8569ffe9aa;hpb=984dc9c8adc66d4ed982e76391db751dd685f0b2;p=poolifier.git diff --git a/src/pools/worker-node.ts b/src/pools/worker-node.ts index 3b69d385..4349ed72 100644 --- a/src/pools/worker-node.ts +++ b/src/pools/worker-node.ts @@ -2,6 +2,7 @@ import { MessageChannel } from 'node:worker_threads' import { CircularArray } from '../circular-array' import { Queue } from '../queue' import type { Task } from '../utility-types' +import { DEFAULT_TASK_NAME } from '../utils' import { type IWorker, type IWorkerNode, @@ -87,6 +88,18 @@ implements IWorkerNode { /** @inheritdoc */ public getTaskWorkerUsage (name: string): WorkerUsage | undefined { + if (name === DEFAULT_TASK_NAME && !Array.isArray(this.info.taskFunctions)) { + throw new Error( + 'Cannot get task worker usage for default task function name when task function names list is not yet defined' + ) + } + if ( + name === DEFAULT_TASK_NAME && + Array.isArray(this.info.taskFunctions) && + this.info.taskFunctions.length > 1 + ) { + name = this.info.taskFunctions[1] + } if (!this.tasksUsage.has(name)) { this.tasksUsage.set(name, this.initTaskWorkerUsage(name)) }