2016-09-09 00:00:53 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var cluster = require('cluster');
|
|
|
|
var cstore;
|
|
|
|
//global.Promise = require('bluebird');
|
|
|
|
|
|
|
|
|
|
|
|
if (cluster.isMaster) {
|
|
|
|
|
|
|
|
|
|
|
|
cstore = require('./master').create({
|
|
|
|
name: 'foo-level'
|
|
|
|
});
|
|
|
|
cstore.then(function (db) {
|
|
|
|
db.set('foo', 'bar');
|
|
|
|
});
|
|
|
|
|
2016-09-09 00:29:12 +00:00
|
|
|
cluster.fork();
|
|
|
|
cluster.fork();
|
|
|
|
|
2016-09-09 00:00:53 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
|
|
|
|
|
|
|
cstore = require('./worker').create({
|
|
|
|
name: 'foo-level'
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
cstore.then(function (db) {
|
|
|
|
setTimeout(function () {
|
|
|
|
db.get('foo', function (err, result) {
|
|
|
|
console.log(cluster.isMaster && '0' || cluster.worker.id.toString(), "db.get('foo')", result);
|
|
|
|
|
|
|
|
if (!cluster.isMaster) {
|
|
|
|
process.exit(0);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}, 250);
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('unhandledRejection', function (err) {
|
|
|
|
console.log('unhandledRejection', err);
|
|
|
|
});
|