atomicutil

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2024 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package atomicutil provides Value, a generic version of atomic.Value.

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
}

A Value provides an atomic load and store of a value of type T. The zero value of a Value returns the zero value of T from Load. Once Store has been called, a Value must not be copied.

A Value must not be copied after first use.

func (*Value[T]) Load

func (v *Value[T]) Load() T

Load returns the value set by the most recent Store. It returns the zero value of T if there has been no call to Store for this Value.

func (*Value[T]) Store

func (v *Value[T]) Store(val T)

Store sets the value of the Value to val.

If T is an interface type, all calls to Store for a given Value must use non-nil values of the same concrete type. Store of an inconsistent type panics, as does Store(nil).

func (*Value[T]) Swap

func (v *Value[T]) Swap(new T) (old T)

Swap stores new into the Value and returns the previous value. It returns the zero value of T if the Value is empty.

If T is an interface type, all calls to Swap for a given Value must use non-nil values of the same concrete type. Store of an inconsistent type panics, as does Store(nil).

Jump to

Keyboard shortcuts

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