Skip to content

Commit

Permalink
Implement FusedStream for Interval
Browse files Browse the repository at this point in the history
  • Loading branch information
udoprog committed Jan 5, 2020
1 parent e38b16c commit 6d58acb
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions tokio/src/time/interval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,19 @@ impl Interval {
}
}

#[cfg(feature = "stream")]
impl crate::stream::Stream for Interval {
type Item = Instant;
cfg_stream! {
impl futures_core::FusedStream for Interval {
fn is_terminated(&self) -> bool {
// NB: intervals never terminate.
false
}
}

impl crate::stream::Stream for Interval {
type Item = Instant;

fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Instant>> {
Poll::Ready(Some(ready!(self.poll_tick(cx))))
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Instant>> {
Poll::Ready(Some(ready!(self.poll_tick(cx))))
}
}
}

0 comments on commit 6d58acb

Please sign in to comment.