pub struct RateLimiter { /* private fields */ }Expand description
Token bucket: rate ops/second, starting EMPTY (strict pacing —
a full-bucket start lets a small job burn its whole burst
unthrottled, defeating the point of --rate for short sweeps).
rate == 0 = unlimited.
use kevy_cli::bulk::RateLimiter;
use std::time::{Duration, Instant};
let mut limiter = RateLimiter::new(100); // 100 ops/s
let start = Instant::now();
for _ in 0..5 {
limiter.take();
}
// the bucket starts empty, so even a short burst is paced
assert!(start.elapsed() >= Duration::from_millis(40));Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(rate: u64) -> Self
pub fn new(rate: u64) -> Self
New limiter at rate ops/s (0 = off).
use kevy_cli::bulk::RateLimiter;
let mut unlimited = RateLimiter::new(0);
let start = std::time::Instant::now();
for _ in 0..10_000 {
unlimited.take(); // never blocks
}
assert!(start.elapsed() < std::time::Duration::from_secs(1));Sourcepub fn take(&mut self)
pub fn take(&mut self)
Block until one op is admitted.
use kevy_cli::bulk::RateLimiter;
use std::time::{Duration, Instant};
let mut limiter = RateLimiter::new(50);
let start = Instant::now();
limiter.take(); // the first op already waits for its token (~20 ms)
assert!(start.elapsed() >= Duration::from_millis(15));Trait Implementations§
Auto Trait Implementations§
impl Freeze for RateLimiter
impl RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnsafeUnpin for RateLimiter
impl UnwindSafe for RateLimiter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more