atomicparam

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: Apache-2.0 Imports: 1 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Value

type Value[T comparable] struct {
	// contains filtered or unexported fields
}

Value is type-param version of sync/atomic.Value. T is constrained to be complarable, because internal atomic.Value checks equality by comparison.

Zero Value is invalid, without proceeding Store call.

func NewValue

func NewValue[T comparable]() Value[T]

NewValue returns newly created Value with inner value populated as zero of T.

func (*Value[T]) CompareAndSwap

func (v *Value[T]) CompareAndSwap(old, new T) (swapped bool)

CompareAndSwap does compare-and-swap operation for T.

`swapped` is always false if value is not stored. To avoid this, call Store beforehand or use v initialized by NewValue.

func (*Value[T]) Load

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

Load loads inner value T atomically.

Load panics if value is not stored. Call Store beforehand or use v initialized by NewValue.

func (*Value[T]) Store

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

func (*Value[T]) Swap

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

Swap swaps old value with new atomically.

Swap panics if value is not stored. Call Store beforehand or use v initialized by NewValue.

Jump to

Keyboard shortcuts

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