vegapokerbot/internal/handler/fsm/fsmcore/atomic_value.go

26 lines
394 B
Go
Raw Normal View History

2024-05-09 16:37:50 +03:00
package fsmcore
import "sync/atomic"
type AtomicValue[T any] struct {
ptr atomic.Pointer[T]
}
func NewAtomicValue[T any](val T) *AtomicValue[T] {
value := &AtomicValue[T]{}
value.ptr.Store(&val)
return value
}
func (v *AtomicValue[T]) Load() (result T) {
val := v.ptr.Load()
if val == nil {
return
}
return *val
}
func (v *AtomicValue[T]) Store(value T) {
v.ptr.Store(&value)
}