js-bao-wss-client / LocksAPI
Interface: LocksAPI
Sub-API for named locks (client.locks.*). A lock is a lease on an app-scoped, caller-chosen key: acquire it (non-blocking tryAcquire or blocking acquire), do your exclusive work, renew if it runs long, then release. Leases always carry a TTL, so a crashed holder never wedges the key.
Methods
acquire()
acquire(
key,options):Promise<LockHandle>
Block until the lock is acquired or timeoutMs elapses. Polls the acquire endpoint with jittered backoff (honoring the server's retryAfterMs), then throws LockTimeoutError if it never wins the key within the window.
Parameters
key
string
options
Returns
Promise<LockHandle>
list()
list():
Promise<LockListResult>
List all currently-held locks in the app (requires an admin token).
Returns
Promise<LockListResult>
release()
release(
handle):Promise<ReleaseResult>
Release a held lock. The handle carries its own key.
Parameters
handle
Returns
Promise<ReleaseResult>
renew()
renew(
handle,options):Promise<RenewResult>
Extend a held lease. Returns renewed:false if the handle no longer matches.
Parameters
handle
options
Returns
Promise<RenewResult>
status()
status(
key):Promise<LockStatus>
Current holder of a key, or { held: false } when free/expired.
Parameters
key
string
Returns
Promise<LockStatus>
tryAcquire()
tryAcquire(
key,options):Promise<LockHandle|null>
Single non-blocking attempt. Resolves to the handle on success, or null when the key is currently held by another caller.
Parameters
key
string
options
Returns
Promise<LockHandle | null>