Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions twilight-http-ratelimiting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,18 @@ pub struct Bucket {
pub reset_at: Instant,
}

impl Bucket {
/// Whether the bucket is exhausted.
pub const fn is_exhausted(&self) -> bool {
self.remaining == 0
}

/// Duration until the bucket resets.
pub fn reset_after(&self) -> Duration {
self.reset_at.saturating_duration_since(Instant::now())
}
}

/// Actor run closure pre-enqueue for early [`MaybePermitFuture`] cancellation.
type Predicate = Box<dyn FnOnce(Option<Bucket>) -> bool + Send>;

Expand Down