GitXplorerGitXplorer
w

worker-threads-pool

public
428 stars
18 forks
3 issues

Commits

List of commits on branch master.
Verified
977085db15bf126b79d037814342fb45ac2cd9c7

test: fix 'bug' introduced in Node 10.7.0

wwatson committed 6 years ago
Verified
4f410375f2f1be6c4b2bccdf3dc941b938f7b293

docs: improve README.md

wwatson committed 7 years ago
Verified
8ccc72dd0b9dcb2748f6bf2c611aa9f3d8b6bba2

2.0.0

wwatson committed 7 years ago
Verified
72cb6e9645fa87980a6412da5bc598ea5f4deb90

test: fix spelling

wwatson committed 7 years ago
Verified
2c6d2301089da3450b77b2dfe199dd9d470a6288

Add maxWaiting config option

wwatson committed 7 years ago
Verified
d9ab4ba041f401ec6d7b437620a5dbf11031f80f

Make pool.acquire options object optional

wwatson committed 7 years ago

README

The README file for this repository.

worker-threads-pool

Easily manage a pool of Node.js Worker Threads.

npm Build status js-standard-style

Installation

npm install worker-threads-pool --save

Prerequisites

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 to run node with the --experimental-worker flag:

node --experimental-worker app.js

Usage

const Pool = require('worker-threads-pool')

const pool = new Pool({max: 5})

for (let i = 0; i < 100; i++) {
  pool.acquire('/my/worker.js', function (err, worker) {
    if (err) throw err
    console.log(`started worker ${i} (pool size: ${pool.size})`)
    worker.on('exit', function () {
      console.log(`worker ${i} exited (pool size: ${pool.size})`)
    })
  })
}

API

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: 1)
  • maxWaiting - Maximum number of workers waiting to be started when the pool is full. The callback to pool.acquire will be called with an error in case this limit is reached

pool.size

Number of active workers in the pool.

pool.acquire(filename[, options], callback)

The filename and options arguments are passed directly to new Worker(filename, options).

The callback argument will be called with the an optional error object and the worker once it's created.

pool.destroy([callback])

Calls worker.terminate() on all workers in the pool.

Will call the optional callback once all workers have terminated.

License

MIT