Index
type Value
Value is an atomic value holder, which have internal rwmutex to avoid concurrent writes.
Usage:
// Actually, we have a NewValue() constructor,
// but let's show how to use a Value without it.
val := &Value[int]{}
val.Set(1)
if val.Get() == 1 {
log.Println("value is 1")
}
go
type Value[T any] struct {
// contains filtered or unexported fields
}
func NewValue
go
func NewValue[T any](defaultval T) *Value[T]
NewValue is a constructor of Value, which accepts default value.
func (*Value[T]) Context
go
func (a *Value[T]) Context(c func(value T, set func(value T)))
Context locks value mutex and executes provided function with releasing lock in the end.
func (*Value[T]) Get
go
func (a *Value[T]) Get() T
Get locks value mutex and returns current value.
func (*Value[T]) Set
go
func (a *Value[T]) Set(value T)
Set locks value mutex and sets current value.
Generated by gomarkdoc