watcher

package
v0.0.0-...-97ebcb8 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2023 License: Apache-2.0, BSD-3-Clause Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Always

type Always[T any] struct{}

Always implements Updater by always updating the value.

func (Always[T]) Update

func (Always[T]) Update(dst *T, src T) bool

type IfUnequal

type IfUnequal[T comparable] struct{}

func (IfUnequal[T]) Update

func (u IfUnequal[T]) Update(old *T, new T) bool

type Updater

type Updater[T any] interface {
	Update(*T, T) bool
}

type Value

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

Value represents a shared value that can be watched for changes. Methods on a Value may be called concurrently.

The zero Value is ok to use; watchers on the zero value will block until Set is called.

U is used to update the value. U.Update must be callable on the zero value of U.

func NewValue

func NewValue[T any, U Updater[T]](initial T) *Value[T, U]

NewValue creates a new Value holding the given initial value.

func (*Value[T, U]) Close

func (v *Value[T, U]) Close() error

Close closes the Value, unblocking any outstanding watchers. Close always returns nil.

func (*Value[T, U]) Closed

func (v *Value[T, U]) Closed() bool

Closed reports whether the value has been closed.

func (*Value[T, U]) Get

func (v *Value[T, U]) Get() T

Get returns the current value. If the watcher has been closed, it returns the zero value.

func (*Value[T, U]) GetOK

func (v *Value[T, U]) GetOK() (T, bool)

GetOK returns the most recently set value and reports whether it is valid. After v has been closed, GetOK will always return *new(T), false.

func (*Value[T, U]) Set

func (v *Value[T, U]) Set(val T)

Set sets the shared value to val.

func (*Value[T, U]) Watch

func (v *Value[T, U]) Watch() Watcher[T]

Watch returns a Watcher that can be used to watch for changes to the value.

type Watcher

type Watcher[T any] interface {
	Next() bool
	Close()
	Value() T
}

Watcher represents a single watcher of a shared value.

Jump to

Keyboard shortcuts

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