@da440dil/js-locker
Version:
Distributed locking using Redis
20 lines (19 loc) • 534 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Lock = void 0;
class Lock {
constructor(locker, key, token) {
this.locker = locker;
this.key = key;
this.token = token;
}
async lock(ttl) {
const v = await this.locker.lock(this.key, this.token, ttl);
return { ok: v < -2, ttl: v };
}
async unlock() {
const v = await this.locker.unlock(this.key, this.token);
return v === 1;
}
}
exports.Lock = Lock;