X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fthread%2Ffixed.ts;h=c4256bf3b2213d8d7a6a60d7df8a95447576b888;hb=refs%2Ftags%2Fv3.1.15;hp=197830279be020e45741fb00930bb82ffcc12ea3;hpb=07e0c9e591f9fa6715ba94e52c647b7ee3d2b9c7;p=poolifier.git diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 19783027..c4256bf3 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -1,14 +1,18 @@ import { - type MessageChannel, type MessagePort, type TransferListItem, type Worker, isMainThread } from 'node:worker_threads' -import type { MessageValue } from '../../utility-types' -import { AbstractPool } from '../abstract-pool' -import { type PoolOptions, type PoolType, PoolTypes } from '../pool' -import { type WorkerType, WorkerTypes } from '../worker' +import type { MessageValue } from '../../utility-types.js' +import { AbstractPool } from '../abstract-pool.js' +import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js' +import { type WorkerType, WorkerTypes } from '../worker.js' + +/** + * Options for a poolifier thread pool. + */ +export type ThreadPoolOptions = PoolOptions /** * A thread pool with a fixed number of threads. @@ -32,9 +36,10 @@ export class FixedThreadPool< public constructor ( numberOfThreads: number, filePath: string, - protected readonly opts: PoolOptions = {} + opts: ThreadPoolOptions = {}, + maximumNumberOfThreads?: number ) { - super(numberOfThreads, filePath, opts) + super(numberOfThreads, filePath, opts, maximumNumberOfThreads) } /** @inheritDoc */ @@ -57,8 +62,8 @@ export class FixedThreadPool< /** @inheritDoc */ protected sendStartupMessageToWorker (workerNodeKey: number): void { const workerNode = this.workerNodes[workerNodeKey] - const port2: MessagePort = (workerNode.messageChannel as MessageChannel) - .port2 + // eslint-disable-next-line @typescript-eslint/no-non-null-assertion + const port2: MessagePort = workerNode.messageChannel!.port2 workerNode.worker.postMessage( { ready: false, @@ -102,6 +107,16 @@ export class FixedThreadPool< ) } + /** @inheritDoc */ + protected shallCreateDynamicWorker (): boolean { + return false + } + + /** @inheritDoc */ + protected checkAndEmitDynamicWorkerCreationEvents (): void { + /* noop */ + } + /** @inheritDoc */ protected get type (): PoolType { return PoolTypes.fixed