pub struct Timer<RT: Access> { /* private fields */ }Expand description
A Future that represents a timer.
If this future returns Poll::Ready(DeadlinePassed) it means that
the deadline has passed. If it returns Poll::Pending it’s not yet
passed.
Examples
use std::time::Duration;
use heph::actor;
use heph_rt::ThreadLocal;
use heph_rt::timer::Timer;
async fn actor(mut ctx: actor::Context<!, ThreadLocal>) {
// Create a timer, this will be ready once the timeout has passed.
let timeout = Timer::after(&mut ctx, Duration::from_millis(200));
// Wait for the timer to pass.
timeout.await;
println!("200 milliseconds have passed!");
}Implementations
sourceimpl<RT: Access> Timer<RT>
impl<RT: Access> Timer<RT>
sourcepub fn at<M>(ctx: &mut Context<M, RT>, deadline: Instant) -> Timer<RT>ⓘNotable traits for Timer<RT>impl<RT: Access> Future for Timer<RT> type Output = DeadlinePassed;where
RT: Clone,
pub fn at<M>(ctx: &mut Context<M, RT>, deadline: Instant) -> Timer<RT>ⓘNotable traits for Timer<RT>impl<RT: Access> Future for Timer<RT> type Output = DeadlinePassed;where
RT: Clone,
Create a new Timer.
sourcepub fn after<M>(ctx: &mut Context<M, RT>, timeout: Duration) -> Timer<RT>ⓘNotable traits for Timer<RT>impl<RT: Access> Future for Timer<RT> type Output = DeadlinePassed;where
RT: Clone,
pub fn after<M>(ctx: &mut Context<M, RT>, timeout: Duration) -> Timer<RT>ⓘNotable traits for Timer<RT>impl<RT: Access> Future for Timer<RT> type Output = DeadlinePassed;where
RT: Clone,
Create a new timer, based on a timeout.
Same as calling Timer::at(&mut ctx, Instant::now() + timeout).
sourcepub fn has_passed(&self) -> bool
pub fn has_passed(&self) -> bool
Returns true if the deadline has passed.
Trait Implementations
impl<RT: Access> Unpin for Timer<RT>
Auto Trait Implementations
impl<RT> RefUnwindSafe for Timer<RT>where
RT: RefUnwindSafe,
impl<RT> Send for Timer<RT>where
RT: Send,
impl<RT> Sync for Timer<RT>where
RT: Sync,
impl<RT> UnwindSafe for Timer<RT>where
RT: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<F> IntoFuture for Fwhere
F: Future,
impl<F> IntoFuture for Fwhere
F: Future,
type IntoFuture = F
type IntoFuture = F
Which kind of future are we turning this into?
sourcefn into_future(self) -> <F as IntoFuture>::IntoFuture
fn into_future(self) -> <F as IntoFuture>::IntoFuture
Creates a future from a value. Read more