@apiratorjs/locking
Version:
A lightweight library providing both local and distributed locking primitives (mutexes and semaphores) for managing concurrency in Node.js.
41 lines • 1.6 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.InMemoryDistributedRegistry = exports.inMemoryDistributedMutexRegistry = exports.inMemoryDistributedSemaphoreRegistry = void 0;
exports.inMemoryDistributedSemaphoreRegistry = new Map();
exports.inMemoryDistributedMutexRegistry = new Map();
class InMemoryDistributedRegistry {
static listMutexNames() {
return Array.from(exports.inMemoryDistributedMutexRegistry.keys());
}
static listSemaphoreNames() {
return Array.from(exports.inMemoryDistributedSemaphoreRegistry.keys());
}
static clearMutexRegistry() {
exports.inMemoryDistributedMutexRegistry.clear();
}
static clearSemaphoreRegistry() {
exports.inMemoryDistributedSemaphoreRegistry.clear();
}
static hasMutex(name) {
return exports.inMemoryDistributedMutexRegistry.has(name);
}
static hasSemaphore(name) {
return exports.inMemoryDistributedSemaphoreRegistry.has(name);
}
static getMutex(name) {
const mutex = exports.inMemoryDistributedMutexRegistry.get(name);
if (!mutex) {
throw new Error(`Mutex ${name} does not exist`);
}
return mutex;
}
static getSemaphore(name) {
const semaphore = exports.inMemoryDistributedSemaphoreRegistry.get(name);
if (!semaphore) {
throw new Error(`Semaphore ${name} does not exist`);
}
return semaphore;
}
}
exports.InMemoryDistributedRegistry = InMemoryDistributedRegistry;
//# sourceMappingURL=in-memory-distributed-registry.js.map