2PL
In-memory two-phase locking for asynchronous JavaScript functions.
npm install 2pl
Multiple lock keys can be acquired during the lifetime of a lock instance, where release is done in one operation.
var lock = var shared = {} // in-memory lock object shared across instances var l = // new instance, 5 seconds timeout l
API
var l = lock(shared, [options])
Create a new instance with shared
object holding the in-memory locks.
Accepts following options:
ttl
: Time to live (milliseconds) of lock instance for liveness. Defaults to 20 seconds.
l.acquire(key, [callback])
Attempts to acquire a lock, given a string key
.
Accepts an optional callback function, invoked on success or error.
l.extend(ttl, [callback])
Attempts to extend ttl
of lock in milliseconds.
Accepts an optional callback function, invoked on success or error.
l.release([callback])
Attempts to release lock. Accepts an optional callback function, invoked on success or error.
var createLock = lock.creator([options])
Returns a factory function createLock([options])
that create instances under the same shared lock object.
var createLock = lock var l1 = // ttl 5000var l2 = // ttl 500
License
MIT