Documentation ¶
Overview ¶
Package threadsafe contains generic containers that are protected either by Mutexes or atomics underneath the hood.
Index ¶
- type Map
- func (m *Map[K, V]) Delete(k K)
- func (m *Map[K, V]) Do(fn func(mp map[K]V))
- func (m *Map[K, V]) Get(k K) (v V, ok bool)
- func (m *Map[K, V]) Keys() (r []K)
- func (m *Map[K, V]) Len() (l int)
- func (m *Map[K, V]) Put(k K, v V)
- func (m *Map[K, V]) Range(fn func(k K, v V) bool)
- func (m *Map[K, V]) View(fn func(mp map[K]V))
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 implements a simple thread-safe map protected by a mutex.
func NewThreadSafeMap ¶
func NewThreadSafeMap[K comparable, V any](m map[K]V) *Map[K, V]
NewThreadSafeMap returns a thread-safe map instance from a normal map.
func (*Map[K, V]) Do ¶
func (m *Map[K, V]) Do(fn func(mp map[K]V))
Do an action on the thread safe map
func (*Map[K, V]) Keys ¶
func (m *Map[K, V]) Keys() (r []K)
Keys returns the keys of a thread-safe map.
func (*Map[K, V]) Range ¶
Range runs the function fn(k K, v V) bool for each key value pair The keys are determined by a snapshot taken at the beginning of the range call If fn returns false, then the loop stops Only one invocation of fn will be active at one time, the iteration order is unspecified.
Click to show internal directories.
Click to hide internal directories.