From 14c4788e8cd64191b4d1c731690050b7c32e45e6 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Thu, 8 Sep 2016 18:28:48 -0600 Subject: [PATCH] use cluster.on('fork') for adding forks --- README.md | 17 +++++++++++------ master.js | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4977b36..14e140b 100644 --- a/README.md +++ b/README.md @@ -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'; @@ -46,10 +47,12 @@ var cluster = require('cluster'); var cstore = require('cluster-store/master').create({ name: 'foo-store' -, store: null // use default in-memory 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 { diff --git a/master.js b/master.js index a4953da..6f3bf4d 100644 --- a/master.js +++ b/master.js @@ -14,5 +14,6 @@ module.exports.create = function (opts) { ] , name: 'memstore.' + (opts.name || '') , master: opts.master + , addOnFork: opts.addOnFork }); };