Fixes to connectors initializing handling.
[e-mobility-charging-stations-simulator.git] / src / charging-station / Worker.js
index 4b7c68ed6b777a8767467a323df928f29fb8a5c7..db82e8215fd0dad8fca89da13431c36f3c5c195d 100644 (file)
@@ -1,4 +1,5 @@
 const Configuration = require('../utils/Configuration');
+const EventEmitter = require('events');
 const {Worker} = require('worker_threads');
 const Pool = require('worker-threads-pool');
 
@@ -8,13 +9,30 @@ class Wrk {
    *
    * @param {String} workerScript
    * @param {Object} workerData
+   * @param {Number} numConcurrentWorkers
    */
-  constructor(workerScript, workerData) {
+  constructor(workerScript, workerData, numConcurrentWorkers) {
+    this._workerData = workerData;
+    this._workerScript = workerScript;
+    this._numConcurrentWorkers = numConcurrentWorkers;
     if (Configuration.useWorkerPool()) {
       this._pool = new Pool({max: Configuration.getWorkerPoolSize()});
     }
-    this._workerData = workerData;
-    this._workerScript = workerScript;
+  }
+
+  /**
+   * @param {Number} numConcurrentWorkers
+   * @private
+   */
+  set _numConcurrentWorkers(numConcurrentWorkers) {
+    if (numConcurrentWorkers > 10) {
+      EventEmitter.defaultMaxListeners = numConcurrentWorkers + 1;
+    }
+    this._concurrentWorkers = numConcurrentWorkers;
+  }
+
+  get _numConcurrentWorkers() {
+    return this._concurrentWorkers;
   }
 
   /**