diff options
author | EuAndreh <eu@euandre.org> | 2025-02-09 17:27:29 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-02-09 17:39:09 -0300 |
commit | 093884c5fdd71d9f96e7bd1f70eef61368ad949a (patch) | |
tree | 4b7cd05e1f44cbff552e4a2adb1ce045e5862c98 | |
parent | Move benchmarks from tests/stm.go to tests/benchmarks/* (diff) | |
download | stm-093884c5fdd71d9f96e7bd1f70eef61368ad949a.tar.gz stm-093884c5fdd71d9f96e7bd1f70eef61368ad949a.tar.xz |
src/stm.go: Add Atom() alias to NewVar() fn
-rw-r--r-- | src/stm.go | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -350,6 +350,11 @@ func Deref[T any](v *Var[T]) T { return v.value.Load().Get().(T) } +// AtomicGet is a helper function that atomically reads a value. +func (ref *AtomT[T]) Deref() T { + return ref.value.Load().Get().(T) +} + // AtomicSet is a helper function that atomically writes a value. func AtomicSet[T any](v *Var[T], val T) { v.mu.Lock() @@ -739,6 +744,14 @@ func NewVar[T any](val T) *Var[T] { return v } +type AtomT[T any] struct{ + *Var[T] +} + +func Atom[T any](x T) *AtomT[T] { + return &AtomT[T]{NewVar(x)} +} + func NewCustomVar[T any](val T, changed func(T, T) bool) *Var[T] { v := &Var[T]{} v.value.Store(customVarValue[T]{ |