Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Atomic ¶
type Atomic[K comparable, T constraints.Integer] interface { Get(key K) (*AtomicValue[T], bool) GetOrCreate(key K, createT T) *AtomicValue[T] Delete(key K) ForEach(fn func(key K, value *AtomicValue[T])) Clear() }
func NewAtomic ¶
func NewAtomic[K comparable, T constraints.Integer]() Atomic[K, T]
type AtomicValue ¶
type AtomicValue[T constraints.Integer] struct { // contains filtered or unexported fields }
func (*AtomicValue[T]) Add ¶
func (a *AtomicValue[T]) Add(v T) T
func (*AtomicValue[T]) Load ¶
func (a *AtomicValue[T]) Load() T
func (*AtomicValue[T]) Store ¶
func (a *AtomicValue[T]) Store(v T)
type Map ¶
type Map[K comparable, T any] interface { Clear() Delete(key K) Load(key K) (T, bool) LoadAndDelete(key K) (T, bool) Range(fn func(key K, value T) bool) Store(key K, value T) Len() int Keys() []K }
Map is a simple _typed_ map which is safe for concurrent use. Favoured over sync.Map as it is typed.
func NewMap ¶
func NewMap[K comparable, T any]() Map[K, T]
type Mutex ¶
type Mutex[T comparable] interface { Lock(key T) Unlock(key T) RLock(key T) RUnlock(key T) Delete(key T) Clear() ItemCount() int DeleteUnlock(key T) DeleteRUnlock(key T) }
Mutex is an interface that defines a thread-safe map with keys of type T associated to read-write mutexes (sync.RWMutex), allowing for granular locking on a per-key basis. This can be useful for scenarios where fine-grained concurrency control is needed.
Methods: - Lock(key T): Acquires an exclusive lock on the mutex associated with the given key. - Unlock(key T): Releases the exclusive lock on the mutex associated with the given key. - RLock(key T): Acquires a read lock on the mutex associated with the given key. - RUnlock(key T): Releases the read lock on the mutex associated with the given key. - Delete(key T): Removes the mutex associated with the given key from the map. - Clear(): Removes all mutexes from the map. - ItemCount() int: Returns the number of items (mutexes) in the map. - DeleteUnlock(key T): Removes the mutex associated with the given key from the map and releases the lock. - DeleteRUnlock(key T): Removes the mutex associated with the given key from the map and releases the read lock.
func NewMutex ¶
func NewMutex[T comparable]() Mutex[T]