gate

package standard library
go1.27.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package gate contains an alternative condition variable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

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.

Jump to

Keyboard shortcuts

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