UNPKG

@apiratorjs/locking

Version:

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

24 lines 709 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Mutex = void 0; const semaphore_1 = require("./semaphore"); class Mutex { constructor() { this._semaphore = new semaphore_1.Semaphore(1); } async runExclusive(...args) { // @ts-ignore return this._semaphore.runExclusive(...args); } async acquire(params, acquireToken) { return this._semaphore.acquire(params, acquireToken); } async cancel(errMessage) { return this._semaphore.cancelAll(errMessage ?? "Mutex cancelled"); } async isLocked() { return this._semaphore.isLocked(); } } exports.Mutex = Mutex; //# sourceMappingURL=mutex.js.map