NodeJS fork pool with option to use as worker pool
NodeJS fork pool with option to use as worker pool
$ npm install git+https://github.com/lightblade/fpool.gitModule not yet published
- path to forked module
- argv passed to the starting process
- options: very similar to
child_process.spawn, except...
- execPath will be used as the script to launch to node process
- execArgv any node specific launch options
- size maximum number of process to spawn
Send job to next available worker.
The message queue consists of only one exported function.
- fn(job, [callback])
- job assigned job to this worker
- [callback] optional callback of signature function(err, data)
- return either...
- nothing (synchronous call)
- thunk (asynchronous call)
- promise(asynchronous call)
var WorkerPool = require('fpool')
// equivilent to
// spawn('/usr/local/bin/node', [ '--harmony', '/usr/local/bin/coffee', '--argv', 'path/to/module' ])
pool = new WorkerPool('path/to/module', [ '--argv' ], {
execPath: '/usr/local/bin/coffee',
execArgv: '--harmony',
size: 4
})
pool.enqueue('job')(function(err, data) {
// done!
})var onReady = require('fpool/mq')
onReady(function(job, [callback]) {
// sync
return minify(job)
// thunk
return function(callback) {
}
// promise
return new Promise(function(resolve, reject) {
})
})MIT