Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
var state = require('state')({
getLastUpdate : db.get.bind(db, 'lastUpdate'),
setLastUpdate : db.put.bind(db)
})
// 1) EE interface
// receive updates if not connected to master
state.on('update', function (update, ts) {
db.put(update.key, update.value)
})
// replicate updates if connected to master
db.on('update', state.put.bind(state))
// 2) with kv wrapper
var kvStream = kv.createDeltaStream()
// connected as required
state.pipe(kvStream).pipe(state)
// distribute all the things!
state.pipe(net.connect(1234)).pipe(state)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.