Struct heph::timer::Deadline [−][src]
pub struct Deadline<Fut, RT: Access> { /* fields omitted */ }
Expand description
A Future
that wraps another future setting a deadline for it.
When this future is polled it first checks if the deadline has passed, if so
it returns Poll::Ready
(Err(
DeadlinePassed
.into()))
. Otherwise
this will poll the future it wraps.
Notes
This type can also be created using Timer::wrap
, this is useful when
dealing with lifetime issue, e.g. when calling
actor::Context::receive_next
and wrapping that in a Deadline
.
Examples
Setting a timeout for a future.
use std::io; use std::time::Duration; use heph::actor; use heph::rt::ThreadSafe; use heph::timer::Deadline; async fn actor(mut ctx: actor::Context<String, ThreadSafe>) { // `OtherFuture` is a type that implements `Future`. let future = IoFuture; // Create our deadline. let deadline_future = Deadline::after(&mut ctx, Duration::from_millis(100), future); // Now we await the results. let result = deadline_future.await; // However the other future is rather slow, so the timeout will pass. assert!(result.is_err()); assert_eq!(result.unwrap_err().kind(), io::ErrorKind::TimedOut); }
Implementations
Create a new Deadline
.
Create a new deadline based on a timeout.
Same as calling Deadline::at(&mut ctx, Instant::now() + timeout, future)
.
Returns true
if the deadline has passed.
Returns the wrapped future.
Trait Implementations
Auto Trait Implementations
impl<Fut, RT> RefUnwindSafe for Deadline<Fut, RT> where
Fut: RefUnwindSafe,
RT: RefUnwindSafe,
impl<Fut, RT> UnwindSafe for Deadline<Fut, RT> where
Fut: UnwindSafe,
RT: UnwindSafe,
Blanket Implementations
type Error = E
type Error = E
An error the actor can return to its supervisor. This error will be considered terminal for this actor and should not be an error of regular processing of a message. Read more
Mutably borrows from an owned value. Read more
into_future
)The output that the future will produce on completion.
type Future = F
type Future = F
into_future
)Which kind of future are we turning this into?
into_future
)Creates a future from a value.