authoritah

Etcd-backed authority lock

Usage no npm install needed!

<script type="module">
  import authoritah from 'https://cdn.skypack.dev/authoritah';
</script>

README

Authoritah

Etcd-backed authority lock for Node.js

Build Status

Cartman

Kind: global class

new Authoritah(key, options)

Param Type Default Description
key string The key to lock against.
options Object
[options.ttl] number 15 The time-to-live of the lock in seconds, after which it expires if not extended.
[options.heartbeatInterval] number 2 The number of seconds between each request to extend lock.
[options.etcd] Etcd Instantiation of node-etcd class. If no instance is given, a default one is instantiated.

authoritah.heartbeat()

A helper function for extending the lock in a throttled manner, with an interval specified in the constructor.

Kind: instance method of Authoritah
Example

stream.on('readable', () => { authority.heartbeat(); });

authoritah.ready() ⇒ Promise.<boolean>

Sets authority as ready, and attempt to acquire lock. If the lock is already taken, then another attempt will be made when it is released or expires.

Kind: instance method of Authoritah
Returns: Promise.<boolean> - A promise that will be fulfilled after lock attempt with a boolean indicating whether attempt was successful.

authoritah.release() ⇒ Promise

Releases lock if currently held, and stop making attempts to lock it.

Kind: instance method of Authoritah
Returns: Promise - A promise that will be fulfilled when lock is released, or immediately when lock is not currently ours.

authoritah.extend() ⇒ Promise

Extends lock for another time period defined by the authority's TTL. Calls #ready if authority is not marked as ready. If lock is not ours at the time, this will have no effect.

Kind: instance method of Authoritah
Returns: Promise - Promise that will be fulfilled when the lock is extended or acquired, or immediately if lock is currently not ours.

"acquired"

Fired when lock is acquired.

Kind: event emitted by Authoritah

"lost"

Fired when lock is lost, i.e. stolen or expired. If lock has expired, we assume the authority is not ready and do not make any further attemps to lock.

Kind: event emitted by Authoritah