atomic

package
v1.16.2 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cast

func Cast[M any](src any) (model M, casted bool)

func IsEmpty

func IsEmpty[M any](src any) bool

Types

type Map

type Map[K comparable] interface {
	Load(key K) (value any, ok bool)
	Store(key K, value any)

	LoadOrStore(key K, value any) (actual any, loaded bool)
	LoadAndDelete(key K) (value any, loaded bool)

	Delete(key K)
	Swap(key K, value any) (previous any, loaded bool)

	CompareAndSwap(key K, old, new any) bool
	CompareAndDelete(key K, old any) (deleted bool)

	Range(f func(key K, value any) bool)
}

func NewMapAny

func NewMapAny[K comparable]() Map[K]

type MapTyped

type MapTyped[K comparable, V any] interface {
	Load(key K) (value V, ok bool)
	Store(key K, value V)

	LoadOrStore(key K, value V) (actual V, loaded bool)
	LoadAndDelete(key K) (value V, loaded bool)

	Delete(key K)
	Swap(key K, value V) (previous V, loaded bool)

	CompareAndSwap(key K, old, new V) bool
	CompareAndDelete(key K, old V) (deleted bool)

	Range(f func(key K, value V) bool)
}

func NewMapTyped

func NewMapTyped[K comparable, V any]() MapTyped[K, V]

type Value

type Value[T any] interface {
	SetDefaultLoad(def T)
	SetDefaultStore(def T)

	Load() (val T)
	Store(val T)
	Swap(new T) (old T)
	CompareAndSwap(old, new T) (swapped bool)
}

func NewValue

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

func NewValueDefault

func NewValueDefault[T any](load, store T) Value[T]

Jump to

Keyboard shortcuts

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