import { ISemaphore, ISemaphoreReleaser, TAcquireParams, TAcquireToken, TSemaphoreAcquireParams, TSemaphoreToken } from "./types"; export declare class Semaphore implements ISemaphore { readonly maxCount: number; private availablePermits; private queue; private anyUnlockListeners; private fullyUnlockListeners; private readonly heldPermits; private readonly permits; constructor(maxCount: number); waitForFullyUnlock(): Promise; waitForAnyUnlock(): Promise; runExclusive(fn: () => Promise | T): Promise; runExclusive(params: TAcquireParams, fn: () => Promise | T): Promise; freeCount(): Promise; /** * @param acquireToken Identity for this acquisition. Layers built on top of a * semaphore - a distributed mutex, for instance - pass their own token, so that * one acquisition has one identity all the way down instead of the caller seeing * one token while the releaser holds another. Left out, a fresh uuid is used. */ acquire(params?: TSemaphoreAcquireParams, acquireToken?: TAcquireToken): Promise; /** * Same as acquire(), but resolves to null instead of throwing * TimeoutLockingError, and timeoutMs defaults to 0. */ tryAcquire(params?: TSemaphoreAcquireParams, acquireToken?: TAcquireToken): Promise; restoreReleaser(token: TSemaphoreToken): ISemaphoreReleaser; /** * Cancels pending acquisitions. * * Permits that are already held stay held: their owners are still inside their * critical sections, and handing their permits back here would let extra * acquirers in alongside them. * * Unlock listeners (waitForAnyUnlock / waitForFullyUnlock) keep waiting - the * semaphore is still alive and will notify them once permits come back. */ cancelAll(errMessage?: string): Promise; /** * Called when the semaphore itself goes away: pending acquisitions are * cancelled, held permits are forgotten (their releasers turn into no-ops) and * unlock listeners are resolved, because a semaphore that no longer exists * cannot be held by anybody. Resolving rather than rejecting also * keeps a fire-and-forget `void sem.waitForAnyUnlock()` from turning into an * unhandled rejection. */ dispose(errMessage?: string): Promise; isLocked(): Promise; private holdPermit; /** * Replaces whatever TTL the permit had; Infinity leaves it without one. */ private setPermitTtl; /** * An expiring permit alone is no reason to keep the process running - same as * for acquisition timeouts. With somebody queued it is: the expiry is what * hands them the permit, and nothing else may be left to do it. */ private updateExpiryTimerRef; private updateExpiryTimersRef; private extendPermit; private permitRemainingTtl; /** * Only a token that still holds a permit gives one back. That makes release * idempotent, and keeps a permit that already expired - and may have been * handed to somebody else since - from being released a second time by its * late original holder. */ private releasePermit; } //# sourceMappingURL=semaphore.d.ts.map