Comparing version 0.0.0 to 0.1.0
{ | ||
"name": "bobbin", | ||
"version": "0.0.0", | ||
"description": "easily spool up \"threads\" with bobbin", | ||
"version": "0.1.0", | ||
"description": "easily spool up thread-like worker processes", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "node_modules/.bin/mocha --compilers coffee:coffee-script/register", | ||
"watch-test": "node_modules/.bin/mocha --compilers coffee:coffee-script/register -w" | ||
"watch-test": "node_modules/.bin/mocha --compilers coffee:coffee-script/register -w", | ||
"lint": "node_modules/.bin/coffeelint src/ test/" | ||
}, | ||
"pre-commit": ["test", "lint"], | ||
"repository": { | ||
@@ -32,7 +34,9 @@ "type": "git", | ||
"devDependencies": { | ||
"coffeelint": "^1.8.1", | ||
"expect.js": "^0.3.1", | ||
"mocha": "^2.1.0", | ||
"mockery": "^1.4.0", | ||
"pre-commit": "0.0.9", | ||
"sinon": "^1.12.2" | ||
} | ||
} |
# bobbin | ||
easily spool up node "threads" with bobbin | ||
easily spool up thread-like worker processes in node with bobbin | ||
a work in progress | ||
```javascript | ||
// to create a pool of workers: | ||
var bobbin = require('bobbin'); | ||
var pool = bobbin.create(4); // 4 processes; defaults to os.cpus().length | ||
// to send some work, in this case concatenate two strings: | ||
var left = 'foo', right = 'bar'; | ||
pool.run( | ||
left, right, // you have to explicitly pass variables | ||
function remoteWorkFunction(left, right, callback) { | ||
callback(left + right); | ||
}, | ||
function localCallback(result) { | ||
assert(result === 'foobar'); | ||
} | ||
); | ||
``` | ||
for clarity, the signature of `pool.run` is: | ||
```javascript | ||
pool.run(varsToSend..., workFunction, localCallback) | ||
``` | ||
stuff to keep in mind: | ||
1. calls to `pool.run()` are dispatched to workers in a round-robin fashion | ||
2. you can't send closures to workers, so explicitly send data in the first arguments to `pool.run()`. those arguments will be passed verbatim into your work function. | ||
3. your local callback gets called with whatever your work function calls back with. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
11666
36
6