waiter

package
v0.0.1-beta.3 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: BSD-3-Clause, BSD-3-Clause Imports: 1 Imported by: 0

README

Waiter

Easy-to-use type which makes it fairly easy to wait for an event, e.g. an error. This is significantly easier to use than a Condition variable.

Documentation

Overview

Package waiter - Wait for a broadcast

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Waiter

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

Waiter makes it easy to wait for a broadcast. This is a bit like a sync.Cond, but easier to use. A waiter must not be copied after first use.

func (*Waiter[T]) AlwaysBroadcast

func (w *Waiter[T]) AlwaysBroadcast(e T)

AlwaysBroadcast broadcasts e to all current waiters and saves it such that every new waiter also receives e. This is useful for fatal errors. Calls to AlwaysBroadcast after the first call to AlwaysBroadcast will not update the value returned to waiters.

func (*Waiter[T]) Broadcast

func (w *Waiter[T]) Broadcast(e T)

Broadcast broadcasts e to all current waiters and closes their underlying channels. If AlwaysBroadcast has been called, Broadcast is a no-op.

func (*Waiter[T]) Wait

func (w *Waiter[T]) Wait() T

Wait waits until Broadcast is called and returns the value passed to Broadcast.

func (*Waiter[T]) WaitChan

func (w *Waiter[T]) WaitChan() <-chan T

WaitChan returns a channel which will receive a value when Broadcast is called. The channel is buffered; a call to Broadcast without a receive on the channel will not block or cause leakage.

Jump to

Keyboard shortcuts

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