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
Trait Implementations
sourceimpl<RT: Access> AsyncIterator for Interval<RT>
impl<RT: Access> AsyncIterator for Interval<RT>
type Item = DeadlinePassed
type Item = DeadlinePassed
🔬This is a nightly-only experimental API. (
async_iterator)The type of items yielded by the async iterator.
sourcefn poll_next(
self: Pin<&mut Self>,
_: &mut Context<'_>
) -> Poll<Option<Self::Item>>
fn poll_next(
self: Pin<&mut Self>,
_: &mut Context<'_>
) -> Poll<Option<Self::Item>>
🔬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 moreimpl<RT: Access> Unpin for Interval<RT>
Auto Trait Implementations
impl<RT> RefUnwindSafe for Interval<RT>where
RT: RefUnwindSafe,
impl<RT> Send for Interval<RT>where
RT: Send,
impl<RT> Sync for Interval<RT>where
RT: Sync,
impl<RT> UnwindSafe for Interval<RT>where
RT: UnwindSafe,
Blanket Implementations
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