Created
November 12, 2012 21:01
-
-
Save juliangruber/4061867 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
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