UNPKG

@apiratorjs/locking

Version:

A lightweight library providing both local and distributed locking primitives (mutexes and semaphores) for managing concurrency in Node.js.

52 lines 2.02 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DistributedSemaphore = void 0; const node_assert_1 = __importDefault(require("node:assert")); const in_memory_distributed_semaphore_1 = require("./in-memory-distributed/in-memory-distributed-semaphore"); const in_memory_distributed_registry_1 = require("./in-memory-distributed/in-memory-distributed-registry"); class DistributedSemaphore { constructor(props) { node_assert_1.default.ok(props.maxCount > 0, "maxCount must be greater than 0"); node_assert_1.default.ok(props.name, "DistributedSemaphore requires a non-empty name."); this._implementation = DistributedSemaphore.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 maxCount() { return this._implementation.maxCount; } ; get implementation() { return this._implementation.implementation; } async freeCount() { return this._implementation.freeCount(); } async acquire(params) { return this._implementation.acquire(params); } async cancelAll(errMessage) { return this._implementation.cancelAll(errMessage ?? "Semaphore cancelled"); } async isLocked() { return this._implementation.isLocked(); } } exports.DistributedSemaphore = DistributedSemaphore; DistributedSemaphore.factory = (props) => new in_memory_distributed_semaphore_1.InMemoryDistributedSemaphore(props, in_memory_distributed_registry_1.inMemoryDistributedSemaphoreRegistry); //# sourceMappingURL=distributed-semaphore.js.map