Skip to content

js-bao-wss-client


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 ​

BlockingAcquireOptions

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 ​

LockHandle

Returns ​

Promise<ReleaseResult>


renew() ​

renew(handle, options): Promise<RenewResult>

Extend a held lease. Returns renewed:false if the handle no longer matches.

Parameters ​

handle ​

LockHandle

options ​

AcquireOptions

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 ​

AcquireOptions

Returns ​

Promise<LockHandle | null>

Documentation validated against js-bao-wss-client 3.4.0 · js-bao 0.11.0 · primitive-admin 1.0.62 · primitive-app 3.1.0 — 2026-09-30