grenache-nodejs-http
Version:
Granache Node.js HTTP implementation
43 lines (38 loc) • 815 B
JavaScript
const { Grape } = require('grenache-grape')
const waterfall = require('async/waterfall')
exports.bootTwoGrapes = bootTwoGrapes
function bootTwoGrapes (cb) {
const grape1 = new Grape({
dht_port: 20002,
dht_bootstrap: ['127.0.0.1:20001'],
api_port: 40001
})
const grape2 = new Grape({
dht_port: 20001,
dht_bootstrap: ['127.0.0.1:20002'],
api_port: 30001
})
waterfall([
(cb) => {
grape1.start()
grape1.once('ready', cb)
},
(cb) => {
grape2.start()
grape2.once('node', cb)
}
], () => {
cb(null, [grape1, grape2])
})
}
exports.killGrapes = killGrapes
function killGrapes (grapes, done) {
grapes[0].stop((err) => {
if (err) throw err
grapes[1].stop((err) => {
if (err) throw err
done()
})
})
}