struct Limiter
XuAPI
pub struct Limiter {
}Purpose
Limiter context or state structure.
Public fields
This type has no public fields.
#rateToken-bucket rate limiter (single task; S6 — no `$&` across `xu`). $lim := rate.new(100, 100) // 100 events/s, burst 100 if lim.allow {... } For per-peer limits keep one Limiter per peer on the coordinator task.
struct Limiterpub struct Limiter {
}Limiter context or state structure.
This type has no public fields.
newpub fn new(events_per_sec int, burst int) Limiternew(events_per_sec, burst). burst must be >= 1.
events_per_sec intburst intLimiter — a value of this type
($&Limiter) allowpub fn (l $&Limiter) allow() boolallow consumes one token if available.
l $&LimiterLimiter instance used by this call (exclusive borrow).bool — true or false
($&Limiter) allow_npub fn (l $&Limiter) allow_n(n int) boolallow_n consumes n tokens or none (all-or-nothing).
l $&LimiterLimiter instance used by this call (exclusive borrow).n intbool — true or false
(Limiter) availablepub fn (l Limiter) available() intExecute available on Limiter.
l LimiterLimiter instance used by this call (value receiver).int — a value of this type
(Limiter) sleep_for_hintpub fn (l Limiter) sleep_for_hint() intsleep_for_hint returns a rough ns until one token exists (0 if ready).
l LimiterLimiter instance used by this call (value receiver).int — a value of this type