import { TDistributedLockInfo, ELockDisplayType, TDistributedLockSnapshot, IDistributedMutex, IDistributedRWLock, IDistributedSemaphore, IDistributedLockManager } from "../types"; /** * Process-local implementation of IDistributedLockManager. * * Owns a set of named distributed locks: hands out the same instance for the same * name while that lock is alive, and knows what it handed out - so an application * can ask whether a name is registered, list its locks, cancel everything that * waits on them, or tear them all down on shutdown. * * A manager is an ordinary object, not a global: create one and inject it. Backend * packages (Redis, Postgres, ...) implement IDistributedLockManager themselves * rather than plugging into this class. * * ```ts * const locks = new InMemoryDistributedLockManager(); * await locks.mutex("orders").runExclusive(() => shipOrder()); * * process.on("SIGTERM", () => locks.destroyAll("Shutting down")); * ``` */ export declare class InMemoryDistributedLockManager implements IDistributedLockManager { private readonly managedLocks; /** * Returns the mutex registered under this name, creating it on first use. */ mutex(name: string): IDistributedMutex; /** * Returns the semaphore registered under this name, creating it on first use. * * @throws LockConfigMismatchError if the name is already registered with a * different maxCount - the existing semaphore keeps its capacity, so returning * it would hand out a semaphore that does not behave as asked. */ semaphore(name: string, maxCount: number): IDistributedSemaphore; /** * Returns the read-write lock registered under this name, creating it on first * use. Omitting maxReaders means "whatever the registered lock uses". * * @throws LockConfigMismatchError if maxReaders is given and differs from the * value the lock was registered with. */ readWriteLock(name: string, maxReaders?: number): IDistributedRWLock; /** * Whether a live mutex is registered under this name. */ hasMutex(name: string): boolean; /** * Whether a live semaphore is registered under this name. */ hasSemaphore(name: string): boolean; /** * Whether a live read-write lock is registered under this name. */ hasRWLock(name: string): boolean; /** * Every lock this manager currently holds. Locks destroyed in the meantime are * dropped rather than reported. */ list(): TDistributedLockInfo[]; /** * How many live locks this manager holds, optionally of one kind only. */ count(kind?: ELockDisplayType): number; /** * Same as list(), plus the current state of every lock. Reading state goes * through the lock implementation, so this one is asynchronous. */ snapshot(): Promise; /** * Cancels everything waiting on every registered lock. The locks stay * registered and usable, and locks that are currently held stay held - their * owners are still inside their critical sections. */ cancelAll(errMessage?: string): Promise; /** * Destroys every registered lock and empties the manager. Pending acquisitions * are rejected, handles report isDestroyed, and the next call to mutex() / * semaphore() / readWriteLock() starts a fresh lock. */ destroyAll(errMessage?: string): Promise; private cancelOne; private describe; private keyOf; /** * A lock destroyed behind the manager's back - through its own destroy() - must * not be handed out again, so it is forgotten on the way. */ private takeAlive; private dropDestroyed; private throwIfAnyFailed; } //# sourceMappingURL=in-memory-distributed-lock-manager.d.ts.map