Documentation
¶
Overview ¶
Package csync provides generic thread-safe containers.
Index ¶
- type Map
- func (m *Map[K, V]) Copy() map[K]V
- func (m *Map[K, V]) Del(key K)
- func (m *Map[K, V]) Get(key K) (V, bool)
- func (m *Map[K, V]) GetOrSet(key K, init func() V) V
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) Range(fn func(K, V) bool)
- func (m *Map[K, V]) Reset()
- func (m *Map[K, V]) Set(key K, val V)
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a generic thread-safe map. All operations are guarded by a RWMutex.
func NewMapFrom ¶
func NewMapFrom[K comparable, V any](src map[K]V) *Map[K, V]
NewMapFrom creates a Map pre-populated with entries from src.
func (*Map[K, V]) Copy ¶
func (m *Map[K, V]) Copy() map[K]V
Copy returns a shallow clone of the underlying map.
func (*Map[K, V]) GetOrSet ¶
func (m *Map[K, V]) GetOrSet(key K, init func() V) V
GetOrSet returns the existing value for key if present. Otherwise it calls init(), stores and returns the result.
type Value ¶
type Value[T any] struct { // contains filtered or unexported fields }
Value is a generic thread-safe scalar wrapper. Use it for values that can be read and written concurrently by multiple goroutines.
For pointer, slice, or map types, use Map or Slice instead — those types have reference semantics that a simple mutex guard cannot make safe.