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 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.

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

Performs the conversion.

Performs the conversion.

🔬 This is a nightly-only experimental API. (into_future)

The output that the future will produce on completion.

🔬 This is a nightly-only experimental API. (into_future)

Which kind of future are we turning this into?

🔬 This is a nightly-only experimental API. (into_future)

Creates a future from a value.

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.