"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