pub struct Deadline<Fut, RT: Access> { /* private fields */ }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_rt::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
sourceimpl<Fut, RT: Access> Deadline<Fut, RT>
impl<Fut, RT: Access> Deadline<Fut, RT>
sourcepub fn at<M>(
ctx: &mut Context<M, RT>,
deadline: Instant,
future: Fut
) -> Deadline<Fut, RT>ⓘNotable traits for Deadline<Fut, RT>impl<Fut, RT: Access, T, E> Future for Deadline<Fut, RT>where
Fut: Future<Output = Result<T, E>>,
E: From<DeadlinePassed>, type Output = Result<T, E>;where
RT: Clone,
pub fn at<M>(
ctx: &mut Context<M, RT>,
deadline: Instant,
future: Fut
) -> Deadline<Fut, RT>ⓘNotable traits for Deadline<Fut, RT>impl<Fut, RT: Access, T, E> Future for Deadline<Fut, RT>where
Fut: Future<Output = Result<T, E>>,
E: From<DeadlinePassed>, type Output = Result<T, E>;where
RT: Clone,
Fut: Future<Output = Result<T, E>>,
E: From<DeadlinePassed>, type Output = Result<T, E>;
Create a new Deadline.
sourcepub fn after<M>(
ctx: &mut Context<M, RT>,
timeout: Duration,
future: Fut
) -> Deadline<Fut, RT>ⓘNotable traits for Deadline<Fut, RT>impl<Fut, RT: Access, T, E> Future for Deadline<Fut, RT>where
Fut: Future<Output = Result<T, E>>,
E: From<DeadlinePassed>, type Output = Result<T, E>;where
RT: Clone,
pub fn after<M>(
ctx: &mut Context<M, RT>,
timeout: Duration,
future: Fut
) -> Deadline<Fut, RT>ⓘNotable traits for Deadline<Fut, RT>impl<Fut, RT: Access, T, E> Future for Deadline<Fut, RT>where
Fut: Future<Output = Result<T, E>>,
E: From<DeadlinePassed>, type Output = Result<T, E>;where
RT: Clone,
Fut: Future<Output = Result<T, E>>,
E: From<DeadlinePassed>, type Output = Result<T, E>;
Create a new deadline based on a timeout.
Same as calling Deadline::at(&mut ctx, Instant::now() + timeout, future).
sourcepub fn has_passed(&self) -> bool
pub fn has_passed(&self) -> bool
Returns true if the deadline has passed.
sourcepub fn into_inner(self) -> Fut
pub fn into_inner(self) -> Fut
Returns the wrapped future.
Trait Implementations
sourceimpl<Fut, RT: Access, T, E> Future for Deadline<Fut, RT>where
Fut: Future<Output = Result<T, E>>,
E: From<DeadlinePassed>,
impl<Fut, RT: Access, T, E> Future for Deadline<Fut, RT>where
Fut: Future<Output = Result<T, E>>,
E: From<DeadlinePassed>,
impl<Fut: Unpin, RT: Access> Unpin for Deadline<Fut, RT>
Auto Trait Implementations
impl<Fut, RT> RefUnwindSafe for Deadline<Fut, RT>where
Fut: RefUnwindSafe,
RT: RefUnwindSafe,
impl<Fut, RT> Send for Deadline<Fut, RT>where
Fut: Send,
RT: Send,
impl<Fut, RT> Sync for Deadline<Fut, RT>where
Fut: Sync,
RT: Sync,
impl<Fut, RT> UnwindSafe for Deadline<Fut, RT>where
Fut: UnwindSafe,
RT: UnwindSafe,
Blanket Implementations
sourceimpl<Fut, O, E> Actor for Futwhere
Fut: Future<Output = O>,
O: ActorResult<Error = E>,
impl<Fut, O, E> Actor for Futwhere
Fut: Future<Output = O>,
O: ActorResult<Error = E>,
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
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