atomic

package
v0.0.0-...-24ca9bf Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2022 License: MIT Imports: 3 Imported by: 0

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 AInt64

type AInt64 interface {
}

type Adder

type Adder[T comparable] interface {
	Add(v T)
}

type Counter

type Counter interface {
	Get() int64
	IncDecer
}

type Decer

type Decer interface {
	Dec()
}

type IncDecer

type IncDecer interface {
	Incer
	Decer
}

type Incer

type Incer interface {
	Inc()
}

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.

Jump to

Keyboard shortcuts

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