cond

package
v0.4.37 Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2024 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package cond implements a context-aware condition variable.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cond

type Cond struct {
	L sync.Locker
	// contains filtered or unexported fields
}

Cond is a context-aware version of a sync.Cond. Like a sync.Cond, a Cond must not be copied after first use.

func NewCond

func NewCond(l sync.Locker) *Cond

NewCond returns a new Cond with Locker l.

func (*Cond) Broadcast

func (c *Cond) Broadcast()

Broadcast is identical to sync.Cond.Broadcast.

func (*Cond) Signal

func (c *Cond) Signal()

Signal is identical to sync.Cond.Signal.

func (*Cond) Wait

func (c *Cond) Wait(ctx context.Context) error

Wait behaves identically to sync.Cond.Wait, except that it respects the provided context. Specifically, if the context is cancelled, c.L is reacquired and ctx.Err() is returned. Example usage:

for !condition() {
    if err := cond.Wait(ctx); err != nil {
        // The context was cancelled. cond.L is locked at this point.
        return err
    }
    // Wait returned normally. cond.L is still locked at this point.
}

Jump to

Keyboard shortcuts

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