-
I already have add |
Beta Was this translation helpful? Give feedback.
Answered by
Darksonn
Dec 25, 2020
Replies: 1 comment
-
The let stream = async_stream::stream! {
loop {
yield interval.tick().await;
}
}; You can also implement use tokio::time::{Interval, Instant};
use std::pin::Pin;
use std::task::{Context, Poll};
use tokio_stream::Stream;
struct MyInterval {
int: Interval,
}
impl Stream for MyInterval {
type Item = Instant;
fn poll_next(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Instant>> {
self.int.poll_tick(cx).map(|inner| Some(inner))
}
} The |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
Darksonn
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The
tokio-stream
crate cannot add an impl ofStream
totokio::time::Interval
because neither the trait nor the type is defined intokio-stream
. Instead you can use theasync-stream
crate to turn it into a stream.You can also implement
Stream
on your wrapper type like this: