Skip to content

Instantly share code, notes, and snippets.

@juliangruber
Created November 15, 2012 10:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliangruber/d0cdfd9160a21b78a4ee to your computer and use it in GitHub Desktop.
Save juliangruber/d0cdfd9160a21b78a4ee to your computer and use it in GitHub Desktop.
synchronized vector clock
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)
@dominictarr
Copy link

I don't understand what a.ancestor(b) is for, or a.moreUpdates(b) does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment