1
0
mirror of https://git.stamm.me/OpenServer/NodeLogging.git synced 2024-09-28 06:17:06 +00:00
nodelogging/out/lock.js

37 lines
882 B
JavaScript
Raw Normal View History

2018-08-09 17:52:01 +00:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
class Lock {
constructor() {
this._locked = false;
this.toCome = [];
this.release = this.release.bind(this);
}
get locked() {
return this._locked;
}
async getLock() {
if (!this._locked)
return { release: this.lock() };
else {
return new Promise((resolve) => {
this.toCome.push(() => {
resolve({ release: this.lock() });
});
});
}
}
lock() {
this._locked = true;
return this.release;
}
async release() {
if (this.toCome.length > 0) {
this.toCome.shift()();
}
else {
this._locked = false;
}
}
}
exports.default = Lock;
//# sourceMappingURL=lock.js.map