pub struct Interval<RT: Access> { /* private fields */ }
Expand description

An AsyncIterator that yields an item after an interval has passed.

This itertor will never return None, it will always set another deadline and yield another item after the deadline has passed.

Notes

The next deadline will always will be set after this returns Poll::Ready. This means that if the interval is very short and the iterator is not polled often enough it’s possible that the actual time between yielding two values can become bigger then the specified interval.

Examples

The following example will print hello world (roughly) every 200 milliseconds.

use std::time::Duration;

use heph::actor;
use heph_rt::ThreadLocal;
use heph_rt::timer::Interval;
use heph_rt::util::next;

async fn actor(mut ctx: actor::Context<!, ThreadLocal>) {
    let mut interval = Interval::every(&mut ctx, Duration::from_millis(200));
    loop {
        // Wait until the next timer expires.
        let _ = next(&mut interval).await;
        println!("Hello world");
    }
}

Implementations

Create a new Interval.

Returns the next deadline for this Interval.

Trait Implementations

🔬This is a nightly-only experimental API. (async_iterator)
The type of items yielded by the async iterator.
🔬This is a nightly-only experimental API. (async_iterator)
Attempt to pull out the next value of this async iterator, registering the current task for wakeup if the value is not yet available, and returning None if the async iterator is exhausted. Read more
🔬This is a nightly-only experimental API. (async_iterator)
Returns the bounds on the remaining length of the async iterator. Read more
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

Auto Trait Implementations

Blanket Implementations

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