Created
July 18, 2018 10:29
-
-
Save fsteff/62afca979806bfbca1ced9bd3b0d7563 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const hyperdb = require('hyperdb') | |
const ram = require('random-access-memory') | |
function create (key, opts) { | |
opts = opts || {valueEncoding: 'utf-8'} | |
return hyperdb(ram, key, opts) | |
} | |
function replicate (a, b, opts) { | |
opts = opts || {live: true} | |
var stream = a.replicate(opts) | |
return stream.pipe(b.replicate(opts)).pipe(stream) | |
} | |
const a = create() | |
let b = null | |
a.ready(() => { | |
console.log('a is ready') | |
a.put('hello', 'world', null, (err) => { | |
if (err) return console.error(err) | |
console.log('hello world written to a') | |
b = create(a.key) | |
b.ready(onB) | |
}) | |
}) | |
function onB (err) { | |
if (err) return console.error(err) | |
console.log('b is ready') | |
replicate(a, b) | |
// throws an error somewhere here (while replication) - I guess the message header is invalid | |
// either "Remote sent invalid feed message", "Remote message is larger than 8MB (max allowed)" or | |
// "Only 128 feeds currently supported" | |
b.get('hello', null, (err, data) => { | |
if (err) return console.err(err) | |
console.log(data[0].value) | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment