X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=lib%2Ffixed.js;h=63e62bade18bf12d7779186516e30445e5e1eaaa;hb=2899629e79cdce584d3c46d6021798eeb85dad9e;hp=95fe686218c5758997cf1111e2f8148d08e32f6d;hpb=8a306b856cd85a189f6ff9b232852726e2850b4e;p=poolifier.git diff --git a/lib/fixed.js b/lib/fixed.js index 95fe6862..63e62bad 100644 --- a/lib/fixed.js +++ b/lib/fixed.js @@ -17,7 +17,7 @@ class FixedThreadPool { * * @param {Number} numThreads Num of threads for this worker pool * @param {string} a file path with implementation of @see ThreadWorker class - * @param {Object} an object with possible options for example errorHandler, onlineHandler, exitHandler + * @param {Object} an object with possible options for example errorHandler, onlineHandler. */ constructor (numThreads, filename, opts) { if (!isMainThread) throw new Error('Cannot start a thread pool from a worker thread !!!') @@ -84,8 +84,7 @@ class FixedThreadPool { const worker = new Worker(path.resolve(this.filename), { env: SHARE_ENV }) worker.on('error', this.opts.errorHandler || empty) worker.on('online', this.opts.onlineHandler || empty) - // TODO remove the workers array , use only the map data structure - // handle properly when a thread exit + // TODO handle properly when a thread exit worker.on('exit', this.opts.exitHandler || empty) this.workers.push(worker) const { port1, port2 } = new MessageChannel() @@ -94,7 +93,7 @@ class FixedThreadPool { worker.port2 = port2 // we will attach a listener for every task, // when task is completed the listener will be removed but to avoid warnings we are increasing the max listeners size - worker.port2.setMaxListeners(this.opts.maxTasks) + worker.port2.setMaxListeners(this.opts.maxTasks || 1000) // init tasks map this.tasks.set(worker, 0) return worker