GitXplorerGitXplorer
m

voter

public
15 stars
2 forks
0 issues

Commits

List of commits on branch master.
Unverified
2dac35b7c5ef59dfe9146c87442fe538773e8382

Add Travis badge to README

mmmalecki committed 11 years ago
Unverified
cf1a69f48162405415d443a0c78c8814bbc18b73

Add .travis.yml

mmmalecki committed 11 years ago
Unverified
9f74702d7d07fd72bed6f3c9770a69943baeac9d

Add tests

mmmalecki committed 11 years ago
Unverified
2989822bb9efc76870c4ed48612c9c0e1882e5a8

Emit `quorum` event after removing voting from the store

mmmalecki committed 11 years ago
Unverified
ca2e2970b8b27c7d569da23790baf8775f02f7d0

Bump version to 0.0.1

mmmalecki committed 11 years ago
Unverified
e09b7cf759dd3ff3c6ec563e9b142a03ebc1aba9

Add basic implementation

mmmalecki committed 11 years ago

README

The README file for this repository.

voter

Build Status

Distributed voting based on Scuttlebutt

Installation

npm install voter

Usage

var Voter = require('voter');

var timeout = 100;

function onNew(key, voting) {
  console.log(this.id + ': voting ' + key + ' with quorum ' + voting.quorum + ' started');
  setTimeout(function () {
    this.vote(key, true);
  }.bind(this), timeout += 100);
}

function onVote(key, origin, vote) {
  console.log(this.id + ': ' + origin + ' voted: ' + JSON.stringify(vote));
}

function onQuorum(key, vote) {
  console.log(this.id + ': voting ' + key + ' reached quorum: ' + JSON.stringify(vote));
}

var a = new Voter();
var b = new Voter();
var c = new Voter();

a.on('new', onNew);
b.on('new', onNew);
c.on('new', onNew);

a.on('vote', onVote);
b.on('vote', onVote);
c.on('vote', onVote);

a.on('quorum', onQuorum);
b.on('quorum', onQuorum);
c.on('quorum', onQuorum);

var ab = a.createStream();
var bc = b.createStream();

ab.pipe(b.createStream()).pipe(ab);
bc.pipe(c.createStream()).pipe(bc);

a.startVoting('voting', { quorum: 4, timeout: 10000 });

setTimeout(function () {
  var d = new Voter();
  var cd = c.createStream();
  cd.pipe(d.createStream()).pipe(cd);

  d.on('new', onNew);
  d.on('vote', onVote);
  d.on('quorum', onQuorum);

}, 4000);