memory-leader

0.1.1 • Public • Published

Memory leader

Build Status Dependencies Status devDependencies Status NPM NPM downloads

Leader election backed on memory, based on redis-leader. Fully supported API.

Install

npm install memory-leader

Examples

 
const Leader = require('memory-leader');
 

API

new Leader(options)

Create a new Leader

options

ttl Lock time to live in milliseconds (will be automatically released after that time)

wait Time between 2 tries getting elected (ms)

stop (callback)

Release the lock for others.

isLeader (callback)

Tells if he got elected.

callback(err, true/false)

Events

elected when your candidate become leader

revoked when your leader got revoked from his leadership

error when an error occurred, best is to exit your process

How it works

Try to set a semaphore with the ttl given in options.

  • If it succeeds, it gets elected and will renew the semaphore every ttl/2 ms.
  • If it fails or get revoked, it tries to get elected every wait ms.

License

GPLv3

Dependencies (3)

Dev Dependencies (2)

Package Sidebar

Install

npm i memory-leader

Homepage

initbee.com/

Weekly Downloads

0

Version

0.1.1

License

GPLv3

Unpacked Size

8.4 kB

Total Files

5

Last publish

Collaborators

  • gorkaes