docs: refine some comments
[poolifier.git] / src / pools / thread / fixed.ts
index d22d75fb3b5a397e8a2371a700d53d4f243160ba..69b3c3071e487abf1658c454289c7117ee351152 100644 (file)
@@ -1,8 +1,9 @@
 import {
+  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'
@@ -15,7 +16,6 @@ export type ThreadPoolOptions = PoolOptions<Worker>
 
 /**
  * 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)
@@ -27,10 +27,10 @@ export class FixedThreadPool<
 > extends AbstractPool<Worker, Data, Response> {
   /**
    * 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 - The maximum number of threads for this pool.
    */
   public constructor (
     numberOfThreads: number,
@@ -50,12 +50,12 @@ export class FixedThreadPool<
   protected sendToWorker (
     workerNodeKey: number,
     message: MessageValue<Data>,
-    transferList?: TransferListItem[]
+    transferList?: readonly TransferListItem[]
   ): void {
-    this.workerNodes[workerNodeKey].messageChannel?.port1.postMessage(
+    this.workerNodes[workerNodeKey]?.messageChannel?.port1.postMessage(
       {
         ...message,
-        workerId: this.getWorkerInfo(workerNodeKey)?.id
+        workerId: this.getWorkerInfo(workerNodeKey)?.id,
       } satisfies MessageValue<Data>,
       transferList
     )
@@ -70,7 +70,7 @@ export class FixedThreadPool<
       {
         ready: false,
         workerId: this.getWorkerInfo(workerNodeKey)?.id,
-        port: port2
+        port: port2,
       } satisfies MessageValue<Data>,
       [port2]
     )