docs: enhance worker choice strategies description
[poolifier.git] / src / pools / abstract-pool.ts
index 55c380b80c5b92de72bb1c4c87e57f4614c56f37..43abfda76c5ed9d07e3ae98fdecb6e40b5f9b025 100644 (file)
@@ -78,9 +78,9 @@ export abstract class AbstractPool<
    * @param opts - Options for the pool.
    */
   public constructor (
-    public readonly numberOfWorkers: number,
-    public readonly filePath: string,
-    public readonly opts: PoolOptions<Worker>
+    protected readonly numberOfWorkers: number,
+    protected readonly filePath: string,
+    protected readonly opts: PoolOptions<Worker>
   ) {
     if (!this.isMain()) {
       throw new Error('Cannot start a pool from a worker!')
@@ -211,9 +211,6 @@ export abstract class AbstractPool<
     }
   }
 
-  /** @inheritDoc */
-  public abstract get type (): PoolType
-
   /** @inheritDoc */
   public get info (): PoolInfo {
     return {
@@ -249,6 +246,13 @@ export abstract class AbstractPool<
     }
   }
 
+  /**
+   * Pool type.
+   *
+   * If it is `'dynamic'`, it provides the `max` property.
+   */
+  protected abstract get type (): PoolType
+
   /**
    * Gets the worker type.
    */
@@ -353,7 +357,9 @@ export abstract class AbstractPool<
    *
    * The pool filling boolean status.
    */
-  protected abstract get full (): boolean
+  protected get full (): boolean {
+    return this.workerNodes.length >= this.maxSize
+  }
 
   /**
    * Whether the pool is busy or not.
@@ -410,6 +416,7 @@ export abstract class AbstractPool<
     await Promise.all(
       this.workerNodes.map(async (workerNode, workerNodeKey) => {
         this.flushTasksQueue(workerNodeKey)
+        // FIXME: wait for tasks to be finished
         await this.destroyWorker(workerNode.worker)
       })
     )
@@ -535,6 +542,7 @@ export abstract class AbstractPool<
         ) {
           // Kill message received from the worker: no new tasks are submitted to that worker for a while ( > maxInactiveTime)
           this.flushTasksQueue(currentWorkerNodeKey)
+          // FIXME: wait for tasks to be finished
           void (this.destroyWorker(workerCreated) as Promise<void>)
         }
       })