A Gate is a monitor (mutex + condition variable) with one bit of state.
The condition may be either set or unset. Lock operations may be unconditional, or wait for the condition to be set. Unlock operations record the new state of the condition.
type Gate struct {
// contains filtered or unexported fields
}
func New(set bool) Gate
New returns a new, unlocked gate.
func (g *Gate) Lock() (set bool)
Lock acquires the gate unconditionally. It reports whether the condition is set.
func (g *Gate) LockIfSet() (acquired bool)
LockIfSet acquires the gate if and only if the condition is set.
func (g *Gate) Unlock(set bool)
Unlock sets the condition and releases the gate.
func (g *Gate) WaitAndLock(ctx context.Context) error
WaitAndLock waits until the condition is set before acquiring the gate. If the context expires, WaitAndLock returns an error and does not acquire the gate.