Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewValue ¶
func NewValue[T any](example T) atomicvalue[T]
NewValue returns a new atomic.Value that provides an atomic load and store of a consistently typed value.
NewValue performs the initial Store of a new, zero-value variable. The example provides the type only and any value is ignored.
A Value must not be copied after first use.
Types ¶
type Adder ¶
type Adder[T comparable] interface { Add(v T) }
type Value ¶
type Value[T any] interface { // Load returns the value set by the most recent Store. // It returns nil if there has been no call to Store for this Value. Load() T // Store sets the value of the Value to x. // All calls to Store for a given Value must use values of the same concrete type. // Store of an inconsistent type panics, as does Store(nil). Store(val T) // Swap stores new into Value and returns the previous value. It returns nil if // the Value is empty. // // All calls to Swap for a given Value must use values of the same concrete // type. Swap of an inconsistent type panics, as does Swap(nil). Swap(new any) (old T) // CompareAndSwap executes the compare-and-swap operation for the Value. // // All calls to CompareAndSwap for a given Value must use values of the same // concrete type. CompareAndSwap of an inconsistent type panics, as does // CompareAndSwap(old, nil). CompareAndSwap(old, new T) bool }
A Value provides an atomic load and store of a consistently typed value. The zero value for a Value returns nil from Load. Once Store has been called, a Value must not be copied.
A Value must not be copied after first use.
Click to show internal directories.
Click to hide internal directories.