Release 1.0.8
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerStaticPool.ts
index c78768e01360a788f131029025433ee8590a5f9b..7a304b707d62b0083c98ce82795921f5ff92072c 100644 (file)
@@ -14,17 +14,18 @@ export default class WorkerStaticPool<T> extends WorkerAbstract {
    * @param {string} workerScript
    * @param {number} numberOfThreads
    * @param {number} startWorkerDelay
+   * @param {PoolOptions} opts
    */
-  constructor(workerScript: string, numberOfThreads: number, startWorkerDelay?: number) {
+  constructor(workerScript: string, numberOfThreads: number, startWorkerDelay?: number, opts?: PoolOptions<Worker>) {
     super(workerScript, startWorkerDelay);
-    this.pool = StaticPool.getInstance(numberOfThreads, this.workerScript);
+    this.pool = StaticPool.getInstance(numberOfThreads, this.workerScript, opts);
   }
 
   get size(): number {
     return this.pool.workers.length;
   }
 
-  get maxElementsPerWorker(): number {
+  get maxElementsPerWorker(): number | null {
     return null;
   }
 
@@ -47,7 +48,7 @@ export default class WorkerStaticPool<T> extends WorkerAbstract {
 
   /**
    *
-   * @param elementData
+   * @param {T} elementData
    * @returns {Promise<void>}
    * @public
    */
@@ -65,17 +66,14 @@ class StaticPool extends FixedThreadPool<WorkerData> {
     super(numberOfThreads, workerScript, opts);
   }
 
-  public static getInstance(numberOfThreads: number, workerScript: string): StaticPool {
+  public static getInstance(numberOfThreads: number, workerScript: string, opts?: PoolOptions<Worker>): StaticPool {
     if (!StaticPool.instance) {
-      StaticPool.instance = new StaticPool(numberOfThreads, workerScript,
-        {
-          exitHandler: (code) => {
-            if (code !== 0) {
-              console.error(`Worker stopped with exit code ${code}`);
-            }
-          }
+      opts.exitHandler = opts?.exitHandler ?? ((code) => {
+        if (code !== 0) {
+          console.error(`Worker stopped with exit code ${code}`);
         }
-      );
+      });
+      StaticPool.instance = new StaticPool(numberOfThreads, workerScript, opts);
     }
     return StaticPool.instance;
   }