Skip to main content

Module RateLimit

Module RateLimit 

Source
Expand description

Token-bucket rate limiter for per-download bandwidth throttling.

Tokens represent bytes that can be consumed. They refill at refill_rate bytes/second up to capacity. Downloads call consume(bytes).await which parks the task until enough tokens are available, keeping the observed throughput at or below the configured limit while still allowing short bursts up to capacity_factor seconds’ worth of data.

Structs§

TokenBucket
Token-bucket rate limiter. Stores the bucket state; wrap in Arc<RwLock<_>> to share across concurrent download tasks.