-
-
Save juliangruber/d0cdfd9160a21b78a4ee to your computer and use it in GitHub Desktop.
synchronized vector clock
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 clock = require('synchronized-clock')() | |
clock.on('update', function (update) { | |
assert(update.value == 'foo') | |
assert(update.clocks.length > 0) | |
}) | |
/** | |
* a = { | |
* value : 'string', | |
* clocks : { | |
* 'id' : 13, | |
* 'id' : 11 | |
* }, | |
* } | |
*/ | |
clock.on('conflict', function (a, b) { | |
assert(a.value != b.value) | |
a.ancestor(b) | |
a.moreUpdates(b) // precedence given to a | |
return a // or b | |
// calls clock.on('update') with a or b | |
}) | |
clock.set('foo') | |
clockA < clockB // works | |
var stream = clock.createStream() | |
stream.pipe(net.connect(3000)).pipe(stream) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't understand what
a.ancestor(b)
is for, ora.moreUpdates(b)
does.