pub struct LeaseTimerWheel { /* private fields */ }Expand description
Timer wheel that schedules leases to fire at specific wall-clock times.
Construct once, share via Arc. Call [schedule] from producer threads,
call [run_until_shutdown] on a dedicated worker thread.
Implementations§
Source§impl LeaseTimerWheel
impl LeaseTimerWheel
Sourcepub fn new(granularity_ms: u64) -> Self
pub fn new(granularity_ms: u64) -> Self
New wheel with granularity_ms bucket width (minimum 1 ms).
Sourcepub fn schedule(&self, id: LeaseId, expiry: Instant)
pub fn schedule(&self, id: LeaseId, expiry: Instant)
Schedule id to fire at or after expiry.
The expiry is snapped forward to the next granularity boundary so near-simultaneous expirations coalesce into a single wake-up. Re-scheduling an existing id silently replaces the prior entry.
Sourcepub fn run_until_shutdown(&self, handler: impl FnMut(LeaseId) -> bool + Send)
pub fn run_until_shutdown(&self, handler: impl FnMut(LeaseId) -> bool + Send)
Block until shutdown() is called or handler returns false.
For each fired lease id, calls handler(id). If the handler returns
false, the wheel stops immediately (even mid-batch).
CPU: the thread is parked in Condvar::wait_timeout between buckets.
With 10 k idle leases scheduled far in the future the CPU cost is
effectively zero — one wake-up per bucket boundary, not per lease.
Auto Trait Implementations§
impl !Freeze for LeaseTimerWheel
impl RefUnwindSafe for LeaseTimerWheel
impl Send for LeaseTimerWheel
impl Sync for LeaseTimerWheel
impl Unpin for LeaseTimerWheel
impl UnsafeUnpin for LeaseTimerWheel
impl UnwindSafe for LeaseTimerWheel
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request