X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fpools%2Fthread%2Ffixed.ts;h=85c5c9be8f94f4dc1b41ea873d0bbd9e742dac19;hb=3a5027122ca6401ae1d755843b20f714c61e3240;hp=9561cc787a2cddbcb757fa1939cdeea25888a5a0;hpb=799c9e089724b6402ae72e0a60719017055a6669;p=poolifier.git diff --git a/src/pools/thread/fixed.ts b/src/pools/thread/fixed.ts index 9561cc78..85c5c9be 100644 --- a/src/pools/thread/fixed.ts +++ b/src/pools/thread/fixed.ts @@ -1,9 +1,9 @@ import { - type MessagePort, + isMainThread, type TransferListItem, type Worker, - isMainThread } from 'node:worker_threads' + import type { MessageValue } from '../../utility-types.js' import { AbstractPool } from '../abstract-pool.js' import { type PoolOptions, type PoolType, PoolTypes } from '../pool.js' @@ -16,7 +16,6 @@ export type ThreadPoolOptions = PoolOptions /** * A thread pool with a fixed number of threads. - * * @typeParam Data - Type of data sent to the worker. This can only be structured-cloneable data. * @typeParam Response - Type of execution response. This can only be structured-cloneable data. * @author [Alessandro Pio Ardizio](https://github.com/pioardi) @@ -28,10 +27,10 @@ export class FixedThreadPool< > extends AbstractPool { /** * Constructs a new poolifier fixed thread pool. - * * @param numberOfThreads - Number of threads for this pool. * @param filePath - Path to an implementation of a `ThreadWorker` file, which can be relative or absolute. * @param opts - Options for this fixed thread pool. + * @param maximumNumberOfThreads */ public constructor ( numberOfThreads: number, @@ -51,10 +50,13 @@ export class FixedThreadPool< protected sendToWorker ( workerNodeKey: number, message: MessageValue, - transferList?: TransferListItem[] + transferList?: readonly TransferListItem[] ): void { - this.workerNodes[workerNodeKey].messageChannel?.port1.postMessage( - { ...message, workerId: this.getWorkerInfo(workerNodeKey)?.id }, + this.workerNodes[workerNodeKey]?.messageChannel?.port1.postMessage( + { + ...message, + workerId: this.getWorkerInfo(workerNodeKey)?.id, + } satisfies MessageValue, transferList ) } @@ -63,13 +65,13 @@ export class FixedThreadPool< protected sendStartupMessageToWorker (workerNodeKey: number): void { const workerNode = this.workerNodes[workerNodeKey] // eslint-disable-next-line @typescript-eslint/no-non-null-assertion - const port2: MessagePort = workerNode.messageChannel!.port2 + const port2 = workerNode.messageChannel!.port2 workerNode.worker.postMessage( { ready: false, workerId: this.getWorkerInfo(workerNodeKey)?.id, - port: port2 - }, + port: port2, + } satisfies MessageValue, [port2] ) }