summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tokio-stream/tests/support/mpsc.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/tokio-stream/tests/support/mpsc.rs')
-rw-r--r--third_party/rust/tokio-stream/tests/support/mpsc.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/third_party/rust/tokio-stream/tests/support/mpsc.rs b/third_party/rust/tokio-stream/tests/support/mpsc.rs
new file mode 100644
index 0000000000..09dbe04215
--- /dev/null
+++ b/third_party/rust/tokio-stream/tests/support/mpsc.rs
@@ -0,0 +1,15 @@
+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)
+}