UNPKG

@apiratorjs/locking-redis

Version:

An extension to the core @apiratorjs/locking library, providing Redis-based implementations of distributed mutexes and semaphores for true cross-process concurrency control in Node.js.

40 lines 1.84 kB
import { RedisClientType } from "redis"; import { types } from "@apiratorjs/locking"; import { IDistributedDeferred, IUnlockWaiter } from "./types"; export declare abstract class BaseDistributedLockPrimitive { readonly name: string; readonly implementation: string; protected readonly redisClient: RedisClientType; protected redisSubscriber?: RedisClientType; protected queue: IDistributedDeferred[]; protected unlockWaiters: Set<IUnlockWaiter>; protected destroyed: boolean; protected constructor(props: { name: string; redisClient: RedisClientType; }); get isDestroyed(): boolean; protected ensureSubscriber(): Promise<void>; /** * Waits until `isSatisfied` holds after a release event. * * Waiters are kept locally and driven by the single `:release` subscription * opened in `ensureSubscriber`. They must never subscribe to that channel * themselves: node-redis appends listeners per `subscribe` call, and * `unsubscribe(channel)` without a listener drops *all* of them - including * the one that drains `queue`. */ protected waitForUnlockEvent(isSatisfied: () => Promise<boolean>): Promise<void>; protected notifyUnlockWaiters(): Promise<void>; protected rejectQueuedAcquirers(error: Error): void; /** * A destroyed lock cannot be held: settle unlock waiters successfully so a * fire-and-forget `void lock.waitForUnlock()` does not become an unhandled * rejection. */ protected resolveUnlockWaiters(): void; protected abstract tryAcquire(ttlMs: number): Promise<types.TAcquireToken | undefined>; protected abstract destroy(): Promise<void>; protected abstract release(token: types.TAcquireToken): Promise<void>; } //# sourceMappingURL=base-distributed-lock-primitive.d.ts.map