X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=src%2Fcharging-station%2FWorker.js;h=cc8358559c5ce29d4bbda526b8de402309203de6;hb=5933cbc8c16288268032886a14e03d47b8ce84f6;hp=4b7c68ed6b777a8767467a323df928f29fb8a5c7;hpb=7dde0b73302613be132c41e1f28a42de555dc2b6;p=e-mobility-charging-stations-simulator.git diff --git a/src/charging-station/Worker.js b/src/charging-station/Worker.js index 4b7c68ed..cc835855 100644 --- a/src/charging-station/Worker.js +++ b/src/charging-station/Worker.js @@ -1,20 +1,38 @@ -const Configuration = require('../utils/Configuration'); -const {Worker} = require('worker_threads'); -const Pool = require('worker-threads-pool'); +import Configuration from '../utils/Configuration.js'; +import EventEmitter from 'events'; +import Pool from 'worker-threads-pool'; +import {Worker} from 'worker_threads'; -class Wrk { +export default class Wrk { /** * Create a new `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; } /** @@ -64,5 +82,3 @@ class Wrk { return this._startWorker(); } } - -module.exports = Wrk;