Align worker code naming.
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerStaticPool.ts
index c6625d8b609ac55d171e5b7959498242289d90d0..ca8c02a0fa613dc1050a18559bd87f82989d16db 100644 (file)
@@ -1,7 +1,8 @@
-import { FixedThreadPool, FixedThreadPoolOptions } from 'poolifier';
+import { FixedThreadPool, PoolOptions } from 'poolifier';
 
 import Constants from '../utils/Constants';
 import Utils from '../utils/Utils';
+import { Worker } from 'worker_threads';
 import { WorkerData } from '../types/Worker';
 import Wrk from './Wrk';
 
@@ -13,9 +14,9 @@ export default class WorkerStaticPool<T> extends Wrk {
    *
    * @param {string} workerScript
    */
-  constructor(workerScript: string, numThreads: number) {
+  constructor(workerScript: string, numberOfThreads: number) {
     super(workerScript);
-    this.pool = StaticPool.getInstance(numThreads, this.workerScript);
+    this.pool = StaticPool.getInstance(numberOfThreads, this.workerScript);
   }
 
   get size(): number {
@@ -34,6 +35,15 @@ export default class WorkerStaticPool<T> extends Wrk {
   // eslint-disable-next-line @typescript-eslint/no-empty-function
   public async start(): Promise<void> { }
 
+  /**
+   *
+   * @return {Promise<void>}
+   * @public
+   */
+  public async stop(): Promise<void> {
+    return this.pool.destroy();
+  }
+
   /**
    *
    * @return {Promise<void>}
@@ -49,13 +59,13 @@ export default class WorkerStaticPool<T> extends Wrk {
 class StaticPool extends FixedThreadPool<WorkerData> {
   private static instance: StaticPool;
 
-  private constructor(numThreads: number, workerScript: string, opts?: FixedThreadPoolOptions) {
-    super(numThreads, workerScript, opts);
+  private constructor(numberOfThreads: number, workerScript: string, opts?: PoolOptions<Worker>) {
+    super(numberOfThreads, workerScript, opts);
   }
 
-  public static getInstance(numThreads: number, workerScript: string): StaticPool {
+  public static getInstance(numberOfThreads: number, workerScript: string): StaticPool {
     if (!StaticPool.instance) {
-      StaticPool.instance = new StaticPool(numThreads, workerScript,
+      StaticPool.instance = new StaticPool(numberOfThreads, workerScript,
         {
           exitHandler: (code) => {
             if (code !== 0) {