1 use async_stream::stream; 2 use tokio::sync::mpsc::{self, UnboundedSender}; 3 use tokio_stream::Stream; 4 unbounded_channel_stream<T: Unpin>() -> (UnboundedSender<T>, impl Stream<Item = T>)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