syncx

package
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package syncx holds small concurrency helpers: a keyed mutex whose entries are freed on release and a bounded LRU cache.

Index

Constants

View Source
const DefaultLRUSize = 1024

DefaultLRUSize is the bound of an LRU whose Size is not set.

Variables

View Source
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.

func (*KeyedMutex) LockWait

func (k *KeyedMutex) LockWait(ctx context.Context, key string, wait time.Duration) (func(), error)

LockWait takes the key's lock, waiting at most wait (≤ 0: no limit) and never past ctx: it returns ErrLockTimeout or ctx's error otherwise (C-23).

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.

func (*LRU[K, V]) Get

func (c *LRU[K, V]) Get(key K) (V, bool)

Get returns the cached value and marks it recently used.

func (*LRU[K, V]) Len

func (c *LRU[K, V]) Len() int

Len is the number of cached entries.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL