A two-level rate limiter for Go that controls both global backend resource access and per-client concurrency.
- Two-level limiting: Global backend semaphore + per-client queues
- Flexible configuration: Per-client limits and timeouts via callback functions
- Type-safe: Generic implementation with comparable key types
- Concurrent-safe: Built for high-concurrency environments
- Memory efficient: Automatic cleanup of unused client semaphores
go get github.com/davidmz/go-doublelimiterlimiter := doublelimiter.New[string](10). // max 10 concurrent backend operations
WithQueue(3). // default 3 operations per client
WithTimeout(5*time.Second) // default 5s timeout
release, err := limiter.Acquire("client-123")
if err != nil {
// Handle ErrQueueFull or ErrTimeout
return
}
defer release() // Always release when done
// Use your backend resource hereFor complete documentation and examples, see GoDoc.
MIT License - see LICENSE file for details.