mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-02 00:00:11 +02:00
time: implement FusedStream for IntervalStream (#7854)
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
use crate::Stream;
|
use crate::Stream;
|
||||||
|
use futures_core::stream::FusedStream;
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
use std::task::{Context, Poll};
|
use std::task::{Context, Poll};
|
||||||
use tokio::time::{Instant, Interval};
|
use tokio::time::{Instant, Interval};
|
||||||
@@ -57,6 +58,12 @@ impl Stream for IntervalStream {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl FusedStream for IntervalStream {
|
||||||
|
fn is_terminated(&self) -> bool {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl AsRef<Interval> for IntervalStream {
|
impl AsRef<Interval> for IntervalStream {
|
||||||
fn as_ref(&self) -> &Interval {
|
fn as_ref(&self) -> &Interval {
|
||||||
&self.inner
|
&self.inner
|
||||||
|
|||||||
@@ -48,3 +48,15 @@ async fn basic_usage() {
|
|||||||
assert_eq!(stream.next().await, None);
|
assert_eq!(stream.next().await, None);
|
||||||
assert_eq!(stream.size_hint(), (0, Some(0)));
|
assert_eq!(stream.size_hint(), (0, Some(0)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::test]
|
||||||
|
#[cfg(feature = "time")]
|
||||||
|
async fn interval_stream_is_never_terminated() {
|
||||||
|
use futures_core::stream::FusedStream;
|
||||||
|
use tokio_stream::wrappers::IntervalStream;
|
||||||
|
|
||||||
|
let interval = tokio::time::interval(std::time::Duration::from_millis(1));
|
||||||
|
let stream = IntervalStream::new(interval);
|
||||||
|
|
||||||
|
assert!(!stream.is_terminated());
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user