Initial support for main configuration file changes handling.
[e-mobility-charging-stations-simulator.git] / src / worker / WorkerFactory.ts
index d71e4227841d5072778c2a7a8a71d256e12ae1e3..fcfe4f80677820266f8438aab242907d281de1ff 100644 (file)
@@ -5,9 +5,13 @@ import WorkerDynamicPool from './WorkerDynamicPool';
 import WorkerSet from './WorkerSet';
 import WorkerStaticPool from './WorkerStaticPool';
 import Wrk from './Wrk';
+import { isMainThread } from 'worker_threads';
 
 export default class WorkerFactory {
   public static getWorkerImpl<T>(workerScript: string, workerProcessType: WorkerProcessType, options?: WorkerOptions): Wrk {
+    if (!isMainThread) {
+      throw new Error('Trying to get a worker implementation outside the main thread');
+    }
     if (Utils.isUndefined(options)) {
       options = {} as WorkerOptions;
     }