latch

package
v0.14.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2026 License: MIT Imports: 2 Imported by: 0

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 New

func New() *Latch

New constructs an untripped Latch with a zero in-flight count.

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.

func (*Latch) Trip

func (l *Latch) Trip()

Trip arms the rendezvous. Idempotent. If the in-flight count is already zero, Done closes immediately.

func (*Latch) Tripped

func (l *Latch) Tripped() bool

Tripped reports whether Trip has been called. Lock-free; one atomic load.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL