Documentation
¶
Overview ¶
Package latch is a one-shot quiescence rendezvous: an in-flight counter and a trip switch. Once tripped, the latch fires — closes Done — the moment the counter reaches zero (immediately, if it already is). The canonical use is graceful drain: stop admitting work, then wait for the work already in flight to finish.
The hot path is lock-free: Inc, Dec, and Tripped are single atomic operations. Trip is idempotent; Done is closed exactly once.
Late increments — an Inc that races past a fired rendezvous — do not re-open Done: callers must check Tripped before Inc, the same admission-gate discipline any drain requires.
Authored in G++ and distributed as generated Go — consumers never need the gpp toolchain.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Latch ¶
type Latch struct {
// contains filtered or unexported fields
}
Latch is the rendezvous. Construct with New; the zero value is not usable.
func (*Latch) Dec ¶
func (l *Latch) Dec()
Dec retires one unit of in-flight work. If the count reaches zero and the latch has been tripped, the rendezvous fires (Done closes). Lock-free on the non-firing path.
func (*Latch) Done ¶
func (l *Latch) Done() <-chan struct{}
Done returns the channel closed when the rendezvous fires: after Trip, once in-flight reaches zero. Before Trip it never closes.
func (*Latch) Inc ¶
func (l *Latch) Inc()
Inc registers one unit of in-flight work. Lock-free. Callers must check Tripped() == false first; see the package comment.