Struct tokio_stream::StreamNotifyClose
source · pub struct StreamNotifyClose<S> { /* private fields */ }
Expand description
A Stream
that wraps the values in an Option
.
Whenever the wrapped stream yields an item, this stream yields that item
wrapped in Some
. When the inner stream ends, then this stream first
yields a None
item, and then this stream will also end.
Example
Using StreamNotifyClose
to handle closed streams with StreamMap
.
use tokio_stream::{StreamExt, StreamMap, StreamNotifyClose};
#[tokio::main]
async fn main() {
let mut map = StreamMap::new();
let stream = StreamNotifyClose::new(tokio_stream::iter(vec![0, 1]));
let stream2 = StreamNotifyClose::new(tokio_stream::iter(vec![0, 1]));
map.insert(0, stream);
map.insert(1, stream2);
while let Some((key, val)) = map.next().await {
match val {
Some(val) => println!("got {val:?} from stream {key:?}"),
None => println!("stream {key:?} closed"),
}
}
}
Implementations§
source§impl<S> StreamNotifyClose<S>
impl<S> StreamNotifyClose<S>
sourcepub fn into_inner(self) -> Option<S>
pub fn into_inner(self) -> Option<S>
Get back the inner Stream
.
Returns None
if the stream has reached its end.