@apiratorjs/locking
Version:
A lightweight library providing both local and distributed locking primitives (mutexes, semaphores, and read-write locks) for managing concurrency in Node.js.
59 lines • 2.27 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DistributedReadWriteLock = void 0;
const in_memory_distributed_read_write_lock_1 = require("./in-memory-distributed/in-memory-distributed-read-write-lock");
const node_assert_1 = __importDefault(require("node:assert"));
class DistributedReadWriteLock {
constructor(props) {
node_assert_1.default.ok(props.name, "DistributedReadWriteLock requires a non-empty name.");
node_assert_1.default.ok(props.maxReaders === undefined || props.maxReaders > 0, "maxReaders must be greater than 0");
this._implementation = DistributedReadWriteLock.factory(props);
}
async maxReaders() {
return this._implementation.maxReaders();
}
async activeReaders() {
return this._implementation.activeReaders();
}
get isDestroyed() {
return this._implementation.isDestroyed;
}
async withReadLock(...args) {
// @ts-ignore
return this._implementation.withReadLock(...args);
}
async withWriteLock(...args) {
// @ts-ignore
return this._implementation.withWriteLock(...args);
}
async destroy() {
return this._implementation.destroy();
}
get name() {
return this._implementation.name;
}
get implementation() {
return this._implementation.implementation;
}
async acquireRead(params) {
return this._implementation.acquireRead(params);
}
async acquireWrite(params) {
return this._implementation.acquireWrite(params);
}
async cancelAll(errMessage) {
return this._implementation.cancelAll(errMessage ?? "ReadWriteLock cancelled");
}
async isReadLocked() {
return this._implementation.isReadLocked();
}
async isWriteLocked() {
return this._implementation.isWriteLocked();
}
}
exports.DistributedReadWriteLock = DistributedReadWriteLock;
DistributedReadWriteLock.factory = (props) => new in_memory_distributed_read_write_lock_1.InMemoryDistributedReadWriteLock(props);
//# sourceMappingURL=distributed-read-write-lock.js.map