use cluster.on('fork') for adding forks

This commit is contained in:
AJ ONeal 2016-09-08 18:28:48 -06:00
parent 7d9730c1c8
commit 14c4788e8c
2 changed files with 12 additions and 6 deletions

View File

@ -35,9 +35,10 @@ The usage is exactly the same as **master**, no changes necessary.
### master
In the **master**/**standalone** process you will create the real store instance
and then in the you must pass each worker via `addWorker()` so that it signals
the worker to create its own rpc-wrapped instance.
In the **master**/**standalone** process you will create the real store instance.
If you need to manually specify which worker will be enabled for this funcitonality
you must set `addOnFork` to `false` and call `addWorker()` manually.
```javascript
'use strict';
@ -47,9 +48,11 @@ var cluster = require('cluster');
var cstore = require('cluster-store/master').create({
name: 'foo-store'
, store: null // use default in-memory store
, addOnFork: true // default
});
cstore.addWorker(cluster.fork());
// if you addOnFork is set to false you can add specific forks manually
//cstore.addWorker(cluster.fork());
cstore.then(function (store) {
store.set('foo', 'bar');
@ -119,11 +122,13 @@ if (cluster.isMaster) {
cstore = require('./master').create({
name: 'foo-level'
});
cstore.addWorker(cluster.fork());
cstore.then(function (store) {
store.put('foo', 'bar');
});
// create as many workers as you need
cluster.fork();
}
else {

View File

@ -14,5 +14,6 @@ module.exports.create = function (opts) {
]
, name: 'memstore.' + (opts.name || '')
, master: opts.master
, addOnFork: opts.addOnFork
});
};