use futures::prelude::*;
use std::fmt;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
#[must_use = "streams do nothing unless polled"]
pub struct Interval {
inner: Pin<Box<dyn runtime_raw::Interval>>,
}
impl Interval {
#[inline]
pub fn new(dur: Duration) -> Self {
let inner = runtime_raw::current_runtime().new_interval(dur);
Self { inner }
}
}
impl Stream for Interval {
type Item = Instant;
#[inline]
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
self.inner.poll_next_unpin(cx)
}
}
impl fmt::Debug for Interval {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
fmt::Debug::fmt(&self.inner, f)
}
}