You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
16 lines
382 B
16 lines
382 B
use async_stream::stream;
|
|
use tokio::sync::mpsc::{self, UnboundedSender};
|
|
use tokio_stream::Stream;
|
|
|
|
pub fn unbounded_channel_stream<T: Unpin>() -> (UnboundedSender<T>, impl Stream<Item = T>) {
|
|
let (tx, mut rx) = mpsc::unbounded_channel();
|
|
|
|
let stream = stream! {
|
|
while let Some(item) = rx.recv().await {
|
|
yield item;
|
|
}
|
|
};
|
|
|
|
(tx, stream)
|
|
}
|