worker-threads-pool2.0.0 • Public • Published
Easily manage a pool of Node.js Worker Threads.
npm install worker-threads-pool --save
Worker Threads in Node.js are still an experimental feature and is only
supported in Node.js v10.5.0 and above. To use Worker Threads, you need
node with the
node --experimental-worker app.js
const Pool =const pool = max: 5for let i = 0; i < 100; i++pool
pool = new Pool([options])
options is an optional object/dictionary with the any of the following properties:
max- Maximum number of workers allowed in the pool. Other workers will be queued and started once there's room in the pool (default:
maxWaiting- Maximum number of workers waiting to be started when the pool is full. The callback to
pool.acquirewill be called with an error in case this limit is reached
Number of active workers in the pool.
pool.acquire(filename[, options], callback)
options arguments are passed directly to
new Worker(filename, options).
callback argument will be called with the an optional error object
and the worker once it's created.
on all workers in the pool.
Will call the optional
callback once all workers have terminated.