UNPKG

@squidcloud/client

Version:

A typescript implementation of the Squid client

45 lines (44 loc) 1.57 kB
import { Observable } from 'rxjs'; /** * Options for acquiring a distributed lock. * @category Platform */ export interface DistributedLockOptions { /** * The maximum time to wait for the lock to be acquired on the server. * @default 2000. */ acquisitionTimeoutMillis?: number; /** * The maximum time the lock can be held before it is automatically released. * If not specified, the lock will be held until explicitly released or the connection is lost. * @default undefined (no limit). */ maxHoldTimeMillis?: number; } /** * A handler for a distributed lock that can be released. * @category Platform */ export interface DistributedLock { /** * Releases the lock by sending a release message to the server. * The release process runs asynchronously. Use `observeRelease()` to be notified when the release completes. * @returns A promise that resolves when the release message is sent, or undefined for backward compatibility. */ release(): Promise<void>; /** * Whether the lock has been released. * @returns True if the lock has been released. */ isReleased(): boolean; /** * Observes when the lock is released (It may be released due to a connection issue) * @returns An observable that emits when the lock is released. */ observeRelease(): Observable<void>; /** The resource identifier (mutex name) that was locked. */ get resourceId(): string; /** Unique lock instance ID within the system. */ get lockId(): string; }