Documentation
¶
Overview ¶
Package ratebucket is the canonical mutex-guarded token bucket shared by the rate-limiters that previously each carried a byte-identical private copy of this algorithm (securex.Bucket, mcpx's bucket, httpx's tokenBucket) — QG-046/QG-059/PERF-0044. Consumers that need different semantics keep their own type: httpx.PeerLimiter (per-IP map + TTL eviction), htpx.rateBucket (lock-free int64/atomic), and wsx.Limiter (sliding-window connection limiter) are deliberately NOT folded in — they are different algorithms, not copies. Code generated by apic; DO NOT EDIT.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bucket ¶
type Bucket struct {
// contains filtered or unexported fields
}
Bucket is a classic token bucket: tokens refill at `rate` per second up to a ceiling of `burst`, and each admitted call consumes one token. Safe for concurrent use.
func (*Bucket) AllowAndSnapshot ¶
AllowAndSnapshot performs the admit decision and captures the snapshot under a single lock acquisition. A canceled context short-circuits to denied without taking the lock (the caller has already blown its deadline).