Skip to content

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).

acquire(): Promise<boolean>

Defined in: src/coordination/Lease.ts:18

Try to acquire the lease. Resolves true on success, false on contention.

Promise<boolean>


checkAlive(): boolean

Defined in: src/coordination/Lease.ts:24

True if this process currently owns the lease. Purely local — no IO.

boolean


onLost(handler): () => void

Defined in: src/coordination/Lease.ts:27

Register a handler fired when ownership is lost unexpectedly.

(reason) => void

() => void


release(): Promise<void>

Defined in: src/coordination/Lease.ts:21

Release the lease voluntarily. No-op if not held.

Promise<void>