mcavage / node-leader

A micro library for performing leader election with zookeeper
7 stars 3 forks source link

increased clarity for readme example? #2

Open DTrejo opened 12 years ago

DTrejo commented 12 years ago

Hey, The example confused me, so this is my attempt to make it more clear, is my clarification correct? Thanks, D

elect(opts, function(err, node) {
   if (node.leader) {
     console.log('Hooray! I am the leader!');
   } else {
+    // you are not the leader, but might be elected at some later time.
     node.on('leader', function() {
-      console.log('I got elected as the leader!');
+      console.log('Old leader is down, and I was just elected as the leader!');
     });
   }
 });

Note that the example will not run out of the box because /my/service/path may not yet exist.

mcavage commented 12 years ago

Yep - that clarification is correct.