chore: switch coding style to JS standard
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerFixedPool.ts
index 9e71c27703442525b1b572f098f6579f71d546ec..a2a0e759d7004f65658d89ff60b684b5d53dad99 100644 (file)
@@ -1,13 +1,13 @@
-import type { EventEmitterAsyncResource } from 'node:events';
+import type { EventEmitterAsyncResource } from 'node:events'
 
-import { FixedThreadPool, type PoolInfo } from 'poolifier';
+import { FixedThreadPool, type PoolInfo } from 'poolifier'
 
-import { WorkerAbstract } from './WorkerAbstract.js';
-import type { WorkerData, WorkerOptions } from './WorkerTypes.js';
-import { randomizeDelay, sleep } from './WorkerUtils.js';
+import { WorkerAbstract } from './WorkerAbstract.js'
+import type { WorkerData, WorkerOptions } from './WorkerTypes.js'
+import { randomizeDelay, sleep } from './WorkerUtils.js'
 
 export class WorkerFixedPool extends WorkerAbstract<WorkerData> {
-  private readonly pool: FixedThreadPool<WorkerData>;
+  private readonly pool: FixedThreadPool<WorkerData>
 
   /**
    * Creates a new `WorkerFixedPool`.
@@ -15,46 +15,48 @@ export class WorkerFixedPool extends WorkerAbstract<WorkerData> {
    * @param workerScript -
    * @param workerOptions -
    */
-  constructor(workerScript: string, workerOptions: WorkerOptions) {
-    super(workerScript, workerOptions);
+  constructor (workerScript: string, workerOptions: WorkerOptions) {
+    super(workerScript, workerOptions)
     this.pool = new FixedThreadPool(
       this.workerOptions.poolMaxSize,
       this.workerScript,
-      this.workerOptions.poolOptions,
-    );
+      this.workerOptions.poolOptions
+    )
   }
 
-  get info(): PoolInfo {
-    return this.pool.info;
+  get info (): PoolInfo {
+    return this.pool.info
   }
 
-  get size(): number {
-    return this.pool.info.workerNodes;
+  get size (): number {
+    return this.pool.info.workerNodes
   }
 
-  get maxElementsPerWorker(): number | undefined {
-    return undefined;
+  get maxElementsPerWorker (): number | undefined {
+    return undefined
   }
 
-  get emitter(): EventEmitterAsyncResource | undefined {
-    return this.pool?.emitter;
+  get emitter (): EventEmitterAsyncResource | undefined {
+    return this.pool?.emitter
   }
 
   /** @inheritDoc */
-  public async start(): Promise<void> {
+  public async start (): Promise<void> {
     // This is intentional
   }
 
   /** @inheritDoc */
-  public async stop(): Promise<void> {
-    return this.pool.destroy();
+  public async stop (): Promise<void> {
+    await this.pool.destroy()
   }
 
   /** @inheritDoc */
-  public async addElement(elementData: WorkerData): Promise<void> {
-    await this.pool.execute(elementData);
+  public async addElement (elementData: WorkerData): Promise<void> {
+    await this.pool.execute(elementData)
     // Start element sequentially to optimize memory at startup
+    // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
     this.workerOptions.elementStartDelay! > 0 &&
-      (await sleep(randomizeDelay(this.workerOptions.elementStartDelay!)));
+      // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
+      (await sleep(randomizeDelay(this.workerOptions.elementStartDelay!)))
   }
 }