mirror of
https://github.com/atlanticbiomedical/biomedjs.git
synced 2025-07-02 00:47:26 -04:00
Latest Code
This commit is contained in:
51
node_modules/strong-store-cluster/lib/master/KeyLock.js
generated
vendored
Normal file
51
node_modules/strong-store-cluster/lib/master/KeyLock.js
generated
vendored
Normal file
@ -0,0 +1,51 @@
|
||||
|
||||
|
||||
module.exports = KeyLock;
|
||||
|
||||
|
||||
function KeyLock(entry, json) {
|
||||
this._entry = entry;
|
||||
this._json = json;
|
||||
this._updated = false;
|
||||
this._released = false;
|
||||
}
|
||||
|
||||
KeyLock.prototype.get = function() {
|
||||
if (!this._json)
|
||||
return undefined;
|
||||
else
|
||||
return JSON.parse(this._json);
|
||||
};
|
||||
|
||||
KeyLock.prototype.set = function(newValue) {
|
||||
if (this._released)
|
||||
throw new Error("Can't set after releasing a lock.");
|
||||
|
||||
this._json = JSON.stringify(newValue);
|
||||
this._updated = true;
|
||||
};
|
||||
|
||||
KeyLock.prototype.del = function() {
|
||||
if (this._released)
|
||||
throw new Error("Can't delete after releasing a lock.");
|
||||
|
||||
this._json = undefined;
|
||||
this._updated = true;
|
||||
};
|
||||
|
||||
KeyLock.prototype.release = function(cb) {
|
||||
if (this._released)
|
||||
throw new Error('KeyLock has already been released.');
|
||||
|
||||
cb = cb || noop;
|
||||
this._released = true;
|
||||
|
||||
if (!this._updated)
|
||||
this._entry.release(-1, cb);
|
||||
else
|
||||
this._entry.setRelease(this._json, -1, cb);
|
||||
};
|
||||
|
||||
|
||||
function noop() {
|
||||
}
|
Reference in New Issue
Block a user