Skip to content

Commit

Permalink
Add isLeader helper method
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfire committed Feb 6, 2017
1 parent aeb88a0 commit aedd3de
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ new Democracy({
Returns the object containing all active nodes and their properties (including the one the method is called from).
#### leader()
Returns the current leader node from the cluster.
#### isLeader()
Returns whether or not the current server is the leader.
#### resign()
If called on the current leader node, will force it to resign as the leader. A new election will be held, which means the same node could be re-elected.
#### send(customEvent, extraData)
Expand Down
11 changes: 10 additions & 1 deletion lib/democracy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* democracy.js
* Copyright (c) 2016, GoldFire Studios, Inc.
* Copyright (c) 2017, GoldFire Studios, Inc.
* http://goldfirestudios.com
*/

Expand Down Expand Up @@ -383,6 +383,15 @@ Democracy.prototype.leader = function() {
return leader;
},

/**
* Check if the current server is the leader or not.
* @return {Boolean} True if this is the leader.
*/
Democracy.prototype.isLeader = function() {
console.log('this id', this._id);
return this._id === this.leader().id;
};

/**
* Safely decode a Buffer message received over UDP.
* @param {Buffer} msg Received data.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"url": "git://github.com/goldfire/democracy.js.git"
},
"main": "index.js",
"version": "1.2.0",
"version": "1.2.1",
"license": {
"type": "MIT",
"url": "https://raw.githubusercontent.com/goldfire/democracy.js/master/LICENSE.md"
Expand Down

0 comments on commit aedd3de

Please sign in to comment.