coordinator

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

ABOUTME: Thread-safe cache with TTL expiration. ABOUTME: Stores expensive operation results to avoid recomputation.

ABOUTME: Resource coordinator for multi-agent systems providing resource locking. ABOUTME: Ensures thread-safe coordination across agent hierarchy.

ABOUTME: Token bucket rate limiter for API call throttling. ABOUTME: Allows bursts up to capacity while maintaining average rate.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache provides thread-safe caching with TTL expiration.

func NewCache

func NewCache() *Cache

NewCache creates a new cache.

func (*Cache) Cleanup

func (c *Cache) Cleanup()

Cleanup removes expired entries. Call periodically.

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all cache entries.

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes a cache entry.

func (*Cache) Get

func (c *Cache) Get(key string) (any, bool)

Get retrieves a value if it exists and hasn't expired. Expired entries are removed on access to prevent memory leaks.

func (*Cache) Set

func (c *Cache) Set(key string, value any, ttl time.Duration)

Set stores a value with the given TTL.

type CachedItem

type CachedItem struct {
	Value     any
	ExpiresAt time.Time
}

CachedItem stores a value with expiration time.

type Coordinator

type Coordinator struct {
	// contains filtered or unexported fields
}

Coordinator manages shared resources across agents.

func New

func New() *Coordinator

New creates a new resource coordinator.

func (*Coordinator) Acquire

func (c *Coordinator) Acquire(ctx context.Context, agentID, resourceID string) error

Acquire attempts to acquire a lock on a resource. Idempotent: if the agent already owns the lock, returns nil.

func (*Coordinator) Release

func (c *Coordinator) Release(agentID, resourceID string) error

Release releases a lock on a resource.

func (*Coordinator) ReleaseAll

func (c *Coordinator) ReleaseAll(agentID string)

ReleaseAll releases all locks held by the given agent.

type RateLimiter

type RateLimiter struct {
	// contains filtered or unexported fields
}

RateLimiter implements token bucket rate limiting.

func NewRateLimiter

func NewRateLimiter(capacity, refillRate float64) *RateLimiter

NewRateLimiter creates a new token bucket rate limiter. capacity: maximum tokens (burst size) refillRate: tokens added per second

func (*RateLimiter) Take

func (r *RateLimiter) Take(ctx context.Context, tokens float64) error

Take consumes tokens, blocking until available or context cancelled.

type ResourceLock

type ResourceLock struct {
	ResourceID string
	OwnerID    string
	AcquiredAt time.Time
}

ResourceLock represents a lock on a shared resource.

Jump to

Keyboard shortcuts

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