Documentation
¶
Overview ¶
Package syncx holds small concurrency helpers: a keyed mutex whose entries are freed on release and a bounded LRU cache.
Index ¶
Constants ¶
const DefaultLRUSize = 1024
DefaultLRUSize is the bound of an LRU whose Size is not set.
Variables ¶
var ErrLockTimeout = errors.New("timed out waiting for the lock")
ErrLockTimeout means LockWait gave up before the key was free.
Functions ¶
This section is empty.
Types ¶
type KeyedMutex ¶
type KeyedMutex struct {
// contains filtered or unexported fields
}
KeyedMutex serializes work per key; a key's entry exists only while it is held or waited for, so the map never grows with the number of keys seen.
func (*KeyedMutex) Len ¶
func (k *KeyedMutex) Len() int
Len is the number of keys currently held or waited for.
func (*KeyedMutex) Lock ¶
func (k *KeyedMutex) Lock(key string) func()
Lock takes the key's lock and returns its release func.
type LRU ¶
type LRU[K comparable, V any] struct { Size int // contains filtered or unexported fields }
LRU is a goroutine-safe cache bounded to Size entries (least recently used evicted; DefaultLRUSize when Size ≤ 0). Size must not change once in use.
func (*LRU[K, V]) Add ¶
func (c *LRU[K, V]) Add(key K, val V)
Add caches a value, evicting the least recently used entries beyond Size.