X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=src%2Fcharging-station%2FWorker.js;h=db82e8215fd0dad8fca89da13431c36f3c5c195d;hb=3da459cca6b1eeb774336a425b637ac47be9a110;hp=5de059d00c6229153937b3d690f7bb7fa444c410;hpb=f7869514b1450a852ff707ba1a3beaecccea9ba7;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Worker.js b/src/charging-station/Worker.js index 5de059d0..db82e821 100644 --- a/src/charging-station/Worker.js +++ b/src/charging-station/Worker.js @@ -9,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; } /** @@ -60,9 +77,6 @@ class Wrk { */ start() { if (Configuration.useWorkerPool()) { - if (Configuration.getWorkerPoolSize() > 10) { - EventEmitter.defaultMaxListeners = Configuration.getWorkerPoolSize() + 1; - } return this._startWorkerWithPool(); } return this._startWorker();