Lease
Defined in: src/coordination/Lease.ts:16
Abstract distributed lease. A lease is owned by a single holder for a bounded duration; renewed periodically by the holder to keep ownership.
Four-method contract:
acquire()tries to claim the lease; returns true on success.release()voluntarily drops ownership.checkAlive()is a cheap “do I still own this lease?” check used by failure-detection logic.onLost(cb)registers a callback fired if ownership is lost unexpectedly (TTL expired, another holder took over, etc.).
Different backends implement the contract differently — see
InMemoryLease (reference + tests) and KubernetesLease (production).
Methods
Section titled “Methods”acquire()
Section titled “acquire()”acquire():
Promise<boolean>
Defined in: src/coordination/Lease.ts:18
Try to acquire the lease. Resolves true on success, false on contention.
Returns
Section titled “Returns”Promise<boolean>
checkAlive()
Section titled “checkAlive()”checkAlive():
boolean
Defined in: src/coordination/Lease.ts:24
True if this process currently owns the lease. Purely local — no IO.
Returns
Section titled “Returns”boolean
onLost()
Section titled “onLost()”onLost(
handler): () =>void
Defined in: src/coordination/Lease.ts:27
Register a handler fired when ownership is lost unexpectedly.
Parameters
Section titled “Parameters”handler
Section titled “handler”(reason) => void
Returns
Section titled “Returns”() => void
release()
Section titled “release()”release():
Promise<void>
Defined in: src/coordination/Lease.ts:21
Release the lease voluntarily. No-op if not held.
Returns
Section titled “Returns”Promise<void>