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

Create a new Deadline.

Create a new deadline based on a timeout.

Same as calling Deadline::at(&mut ctx, Instant::now() + timeout, future).

Returns the deadline set for this Deadline.

Returns true if the deadline has passed.

Returns a reference to the wrapped future.

Returns a mutable reference to the wrapped future.

Returns the wrapped future.

Trait Implementations

Error type used in bind_to. Read more
Bind a type to the Actor that owns the ctx. Read more
Formats the value using the given formatter. Read more
Executes the destructor for this type. Read more
The type of value produced on completion.
Attempt to resolve the future to a final value, registering the current task for wakeup if the value is not yet available. Read more

Auto Trait Implementations

Blanket Implementations

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
Try to poll this actor. Read more
Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The output that the future will produce on completion.
Which kind of future are we turning this into?
Creates a future from a value. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.