Apply prettier formating
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerFactory.ts
index debd3f6a21342797ac15a6ae23eb5f0e664edce5..1c4b81c8ad6ab5d7c0e35a9b89e46d39b4f19c7e 100644 (file)
@@ -13,28 +13,39 @@ export default class WorkerFactory {
     // This is intentional
   }
 
-  public static getWorkerImplementation<T extends WorkerData>(workerScript: string, workerProcessType: WorkerProcessType, workerOptions?: WorkerOptions): WorkerAbstract<T> | null {
+  public static getWorkerImplementation<T extends WorkerData>(
+    workerScript: string,
+    workerProcessType: WorkerProcessType,
+    workerOptions?: WorkerOptions
+  ): WorkerAbstract<T> | null {
     if (!isMainThread) {
       throw new Error('Trying to get a worker implementation outside the main thread');
     }
-    workerOptions = workerOptions ?? {} as WorkerOptions;
-    workerOptions.workerStartDelay = workerOptions?.workerStartDelay ?? Constants.WORKER_START_DELAY;
-    workerOptions.elementStartDelay = workerOptions?.elementStartDelay ?? Constants.ELEMENT_START_DELAY;
-    workerOptions.poolOptions = workerOptions?.poolOptions ?? {} as PoolOptions<Worker>;
-    workerOptions?.messageHandler && (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler);
+    workerOptions = workerOptions ?? ({} as WorkerOptions);
+    workerOptions.workerStartDelay =
+      workerOptions?.workerStartDelay ?? Constants.WORKER_START_DELAY;
+    workerOptions.elementStartDelay =
+      workerOptions?.elementStartDelay ?? Constants.ELEMENT_START_DELAY;
+    workerOptions.poolOptions = workerOptions?.poolOptions ?? ({} as PoolOptions<Worker>);
+    workerOptions?.messageHandler &&
+      (workerOptions.poolOptions.messageHandler = workerOptions.messageHandler);
     let workerImplementation: WorkerAbstract<T> = null;
     switch (workerProcessType) {
       case WorkerProcessType.WORKER_SET:
-        workerOptions.elementsPerWorker = workerOptions?.elementsPerWorker ?? Constants.DEFAULT_CHARGING_STATIONS_PER_WORKER;
+        workerOptions.elementsPerWorker =
+          workerOptions?.elementsPerWorker ?? Constants.DEFAULT_CHARGING_STATIONS_PER_WORKER;
         workerImplementation = new WorkerSet(workerScript, workerOptions);
         break;
       case WorkerProcessType.STATIC_POOL:
-        workerOptions.poolMaxSize = workerOptions?.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE;
+        workerOptions.poolMaxSize =
+          workerOptions?.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE;
         workerImplementation = new WorkerStaticPool(workerScript, workerOptions);
         break;
       case WorkerProcessType.DYNAMIC_POOL:
-        workerOptions.poolMinSize = workerOptions?.poolMinSize ?? Constants.DEFAULT_WORKER_POOL_MIN_SIZE;
-        workerOptions.poolMaxSize = workerOptions?.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE;
+        workerOptions.poolMinSize =
+          workerOptions?.poolMinSize ?? Constants.DEFAULT_WORKER_POOL_MIN_SIZE;
+        workerOptions.poolMaxSize =
+          workerOptions?.poolMaxSize ?? Constants.DEFAULT_WORKER_POOL_MAX_SIZE;
         workerImplementation = new WorkerDynamicPool(workerScript, workerOptions);
         break;
       default: