1use async_stream::stream;
2use tokio::sync::mpsc::{self, UnboundedSender};
3use tokio_stream::Stream;
4
5pub fn unbounded_channel_stream<T: Unpin>() -> (UnboundedSender<T>, impl Stream<Item = T>) {
6 let (tx, mut rx) = mpsc::unbounded_channel();
7
8 let stream = stream! {
9 while let Some(item) = rx.recv().await {
10 yield item;
11 }
12 };
13
14 (tx, stream)
15}
16