@apiratorjs/locking
Version:
A lightweight library providing both local and distributed locking primitives (mutexes and semaphores) for managing concurrency in Node.js.
42 lines • 1.53 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.DistributedMutex = void 0;
const in_memory_distributed_mutex_1 = require("./in-memory-distributed/in-memory-distributed-mutex");
const node_assert_1 = __importDefault(require("node:assert"));
class DistributedMutex {
constructor(props) {
node_assert_1.default.ok(props.name, "DistributedMutex requires a non-empty name.");
this._implementation = DistributedMutex.factory(props);
}
get isDestroyed() {
return this._implementation.isDestroyed;
}
async runExclusive(...args) {
// @ts-ignore
return this._implementation.runExclusive(...args);
}
async destroy() {
return this._implementation.destroy();
}
get name() {
return this._implementation.name;
}
get implementation() {
return this._implementation.implementation;
}
async acquire(params) {
return this._implementation.acquire(params);
}
async cancel(errMessage) {
return this._implementation.cancel(errMessage ?? "Mutex cancelled");
}
async isLocked() {
return this._implementation.isLocked();
}
}
exports.DistributedMutex = DistributedMutex;
DistributedMutex.factory = (props) => new in_memory_distributed_mutex_1.InMemoryDistributedMutex(props);
//# sourceMappingURL=distributed-mutex.js.map