Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrAlreadyExists = fmt.Errorf("map key already exists")
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a thread-safe generic map type
func NewMap ¶
func NewMap[K comparable, V any](initMap map[K]V) Map[K, V]
NewMap constructs a new syncro.Map, initialized from a Go map. It is not necessary to use NewMap if you do not need to set an initial value.
func (*Map[K, V]) Create ¶
Create stores a value into the map, which must not already exist. Returns ErrAlreadyExists if the key exists.
func (*Map[K, V]) Get ¶
Get a value from the map. If it exists, returns the value and true; otherwise, returns the zero value and false.
func (*Map[K, V]) WorkWith ¶
func (m *Map[K, V]) WorkWith(f func(*map[K]V))
WorkWith calls a function to work with the map under lock
func (*Map[K, V]) WorkWithReadOnly ¶
func (m *Map[K, V]) WorkWithReadOnly(f func(map[K]V))
WorkWithReadOnly calls a function to work with the map under lock. You are on the honor system not to change it.
type Var ¶
type Var[T any] struct { // contains filtered or unexported fields }
Var stores a single variable and allows synchronized access
func NewVar ¶
NewVar creates a new variable with a given initial value. It is not required to use NewVar if you don't need to set an initial value.
func (*Var[T]) WorkWith ¶
func (sv *Var[T]) WorkWith(f func(*T))
WorkWith calls a function to work with the data under lock
func (*Var[T]) WorkWithReadOnly ¶
func (sv *Var[T]) WorkWithReadOnly(f func(T))
WorkWithReadOnly calls a function to work with the data under lock. You are on the honor system not to change it.