Struct IdleGuard
pub struct IdleGuard { /* private fields */ }std only.Expand description
An idle deadline: timeout after the last recorded activity.
Activity is recorded by the guard’s owner with IdleGuard::reset, from any task as a
timestamp on an IdleActivity polled with IdleGuard::expired, or from any task as
a count on an IdleProgress polled with IdleGuard::stalled. The timer itself is
only re-armed when it fires and activity moved the deadline since, so recording costs no
timer work per event.
Every wait is cancel safe: dropping it keeps the deadline, so it can be polled again
from every iteration of a tokio::select! loop. Once a wait completed it completes
again at once, until activity is recorded.
A guard can be created outside a Tokio runtime: its timer is armed on the first wait, still at the deadline counted from its creation or the activity it follows.
Implementations§
§impl IdleGuard
impl IdleGuard
pub fn new(timeout: Duration) -> IdleGuard
pub fn new(timeout: Duration) -> IdleGuard
Create a new IdleGuard that fires after timeout of inactivity, counted from now.
Timeouts beyond thirty years are capped there, tokio’s own far future.
pub fn for_activity(timeout: Duration, activity: &IdleActivity) -> IdleGuard
pub fn for_activity(timeout: Duration, activity: &IdleActivity) -> IdleGuard
Create an IdleGuard that fires timeout after the last activity recorded on
activity, for use with IdleGuard::expired.
Timeouts beyond thirty years are capped there, tokio’s own far future.
pub fn reset(&mut self)
pub fn reset(&mut self)
Record activity now, moving the idle deadline to now + timeout.
pub fn tick(&mut self) -> impl Future<Output = ()>
pub fn tick(&mut self) -> impl Future<Output = ()>
Completes once timeout passed since the last IdleGuard::reset.
pub fn poll_tick(&mut self, cx: &mut Context<'_>) -> Poll<()>
pub fn poll_tick(&mut self, cx: &mut Context<'_>) -> Poll<()>
Poll form of IdleGuard::tick, for use within a poll_* method.
pub fn expired<'a>(
&'a mut self,
activity: &'a IdleActivity,
) -> impl Future<Output = ()> + 'a
pub fn expired<'a>( &'a mut self, activity: &'a IdleActivity, ) -> impl Future<Output = ()> + 'a
Completes once timeout passed since the last activity, recorded on activity or
with IdleGuard::reset.
pub fn poll_expired(
&mut self,
cx: &mut Context<'_>,
activity: &IdleActivity,
) -> Poll<()>
pub fn poll_expired( &mut self, cx: &mut Context<'_>, activity: &IdleActivity, ) -> Poll<()>
Poll form of IdleGuard::expired, for use within a poll_* method.
pub fn stalled<'a>(
&'a mut self,
progress: &'a IdleProgress,
) -> impl Future<Output = ()> + 'a
pub fn stalled<'a>( &'a mut self, progress: &'a IdleProgress, ) -> impl Future<Output = ()> + 'a
Completes once a timer of timeout fired without progress counting anything since
it was armed, nor a IdleGuard::reset within timeout: between timeout and twice
it after the last progress.
pub fn poll_stalled(
&mut self,
cx: &mut Context<'_>,
progress: &IdleProgress,
) -> Poll<()>
pub fn poll_stalled( &mut self, cx: &mut Context<'_>, progress: &IdleProgress, ) -> Poll<()>
Poll form of IdleGuard::stalled, for use within a poll_* method.
pub fn stalled_by<'a>(
&'a mut self,
count: impl Fn() -> u64 + 'a,
) -> impl Future<Output = ()> + 'a
pub fn stalled_by<'a>( &'a mut self, count: impl Fn() -> u64 + 'a, ) -> impl Future<Output = ()> + 'a
As IdleGuard::stalled, with progress read from count: a total that starts at
zero and grows with every step of progress, such as bytes moved by its owner.
pub fn poll_stalled_by(
&mut self,
cx: &mut Context<'_>,
count: impl Fn() -> u64,
) -> Poll<()>
pub fn poll_stalled_by( &mut self, cx: &mut Context<'_>, count: impl Fn() -> u64, ) -> Poll<()>
Poll form of IdleGuard::stalled_by, for use within a poll_* method.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for IdleGuard
impl !UnwindSafe for IdleGuard
impl Forget for IdleGuard
impl Freeze for IdleGuard
impl Move for IdleGuard
impl Send for IdleGuardwhere
BoxRaw<Sleep>: Send,
impl Sync for IdleGuardwhere
BoxRaw<Sleep>: Sync,
impl Unpin for IdleGuard
impl UnsafeUnpin for IdleGuard
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§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 more§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a rama_grpc::Request§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more