https://github.com/ming-codes/fpool
https://github.com/ming-codes/fpool
Last synced: 8 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/ming-codes/fpool
- Owner: ming-codes
- Created: 2014-05-27T05:22:35.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2017-02-14T00:54:39.000Z (over 9 years ago)
- Last Synced: 2023-03-12T22:25:26.809Z (over 3 years ago)
- Language: JavaScript
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
NodeJS fork pool with option to use as worker pool
# fpool - Work in Progress
NodeJS fork pool with option to use as worker pool
## Installation
```bash
$ npm install git+https://github.com/lightblade/fpool.git
```
Module not yet published
## API
### WorkerPool
#### constructor
1. path to forked module
2. argv passed to the starting process
3. 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
#### enqueue(job)
Send job to next available worker.
### MessageQueue
The message queue consists of only one exported function.
#### ready(fn)
1. fn(job, [callback])
1. job assigned job to this worker
2. [callback] optional callback of signature function(err, data)
* *return* either...
* nothing (synchronous call)
* thunk (asynchronous call)
* promise(asynchronous call)
## Example
```javascript
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!
})
```
```javascript
var onReady = require('fpool/mq')
onReady(function(job, [callback]) {
// sync
return minify(job)
// thunk
return function(callback) {
}
// promise
return new Promise(function(resolve, reject) {
})
})
```
## License
MIT