gate

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2025 License: BSD-3-Clause Imports: 1 Imported by: 0

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
JackTT - Gopher 🇻🇳