cluster-store.js/test.js

47 lines
766 B
JavaScript
Raw Normal View History

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.addWorker(cluster.fork());
cstore.then(function (db) {
db.set('foo', 'bar');
});
}
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);
});