lease
v1.0.0
Published
In-memory time-released lock for async resources
Downloads
448
Readme
Lease
A memory (RAM) time-released lock for asynchronous resources.
Usage
The following will drop all requests that come in while the lock has been taken out and not yet released.
var Lease = require('./'),
lease = Lease(2000);
function get(cb) {
function criticalSection(err, release) {
if (err) {
if ('AlreadyLeasedError' === err.name) return;
return cb(err);
}
setTimeout(function () {
release();
cb(null, Math.random());
}, 1000);
}
lease('key', criticalSection);
}
It is up to the client to choose what to do when another resource acquired the lease.
API
Lease(timeInMs)