package gate

import "golang.org/x/net/internal/gate"

Package gate contains an alternative condition variable.

Index

Types

type Gate

type Gate struct {
	// contains filtered or unexported fields
}

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.

func New

func New(set bool) Gate

New returns a new, unlocked gate.

func (*Gate) Lock

func (g *Gate) Lock() (set bool)

Lock acquires the gate unconditionally. It reports whether the condition is set.

func (*Gate) LockIfSet

func (g *Gate) LockIfSet() (acquired bool)

LockIfSet acquires the gate if and only if the condition is set.

func (*Gate) Unlock

func (g *Gate) Unlock(set bool)

Unlock sets the condition and releases the gate.

func (*Gate) WaitAndLock

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.

Source Files

gate.go

Version
v0.35.0 (latest)
Published
Feb 10, 2025
Platform
linux/amd64
Imports
1 packages
Last checked
5 hours ago

Tools for package owners.