Documentation
¶
Overview ¶
Package memlease is the in-memory reference port.SessionLease: the offline, clock-injected single-writer lease the conformance suite validates and that composition can wire as the default-store opt-in. It keeps per-session lease records in a mutex-guarded map and derives expiry from an injected port.Clock, so tests advance a fake clock past the TTL to exercise expiry/takeover without real sleeps.
It is the reference for the SAME port.SessionLease contract the flock, gRPC-driver, and k8s adapters implement; the contract is the port, the in-memory map is one adapter.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Lease ¶
type Lease struct {
// contains filtered or unexported fields
}
Lease is a concurrency-safe in-memory SessionLease. The token counter is per-id monotone (advanced on every takeover), so a successful takeover always returns a strictly greater token than any prior grant for that id.
func New ¶
New constructs an in-memory lease with the given TTL and clock. A nil clock or a non-positive ttl is a programming error at the only construction sites (composition, tests), so they are not defended here beyond a sane default ttl.
func (*Lease) Acquire ¶
Acquire grants the lease for id to owner when it is free, expired, or already held by owner; otherwise it returns ErrLeaseHeld. A takeover bumps the per-id token strictly past any prior grant; a same-owner re-acquire keeps the existing token (the hold is unchanged, only the expiry refreshes).