refactor: limit pool internals public exposure
[poolifier.git] / src / pools / abstract-pool.ts
index 58fc28ce12d6a56416b6db05cec3e5186c549a14..538d66c797fabc98e93a130953fdde2ee9edfdc8 100644 (file)
@@ -17,7 +17,8 @@ import {
   type PoolOptions,
   type PoolType,
   PoolTypes,
-  type TasksQueueOptions
+  type TasksQueueOptions,
+  type WorkerType
 } from './pool'
 import type { IWorker, Task, TasksUsage, WorkerNode } from './worker'
 import {
@@ -210,13 +211,11 @@ export abstract class AbstractPool<
     }
   }
 
-  /** @inheritDoc */
-  public abstract get type (): PoolType
-
   /** @inheritDoc */
   public get info (): PoolInfo {
     return {
       type: this.type,
+      worker: this.worker,
       minSize: this.minSize,
       maxSize: this.maxSize,
       workerNodes: this.workerNodes.length,
@@ -247,6 +246,18 @@ export abstract class AbstractPool<
     }
   }
 
+  /**
+   * Pool type.
+   *
+   * If it is `'dynamic'`, it provides the `max` property.
+   */
+  protected abstract get type (): PoolType
+
+  /**
+   * Gets the worker type.
+   */
+  protected abstract get worker (): WorkerType
+
   /**
    * Pool minimum size.
    */
@@ -403,6 +414,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)
       })
     )
@@ -528,6 +540,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>)
         }
       })