wait

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: May 27, 2024 License: MPL-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package wait provides a simple mechanism to wait for a value to be set.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Value

type Value[T any] struct {
	// contains filtered or unexported fields
}

Value is a simple mechanism to wait for a value to be set. It's like semaphore, but for values.

func (*Value[T]) Get

func (wv *Value[T]) Get(ctx context.Context) (T, error)

Get waits for the value to be set and returns it. It returns an error if the context is canceled.

func (*Value[T]) Set

func (wv *Value[T]) Set(value T)

Set sets the value and unblocks any waiting goroutines.

func (*Value[T]) TryGet

func (wv *Value[T]) TryGet() (T, bool)

TryGet returns the value if it is set, or false if it is not.

func (*Value[T]) Unset

func (wv *Value[T]) Unset()

Unset unsets the value. Any Get calls will block until Set is called again.

Jump to

Keyboard shortcuts

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