| Crates.io | multi_stream |
| lib.rs | multi_stream |
| version | 0.1.0 |
| created_at | 2023-06-29 18:24:09.494108+00 |
| updated_at | 2023-06-29 18:24:09.494108+00 |
| description | Aggregate multiple streams of different types in a single stream with an item type that is a tuple of the incoming stream items. |
| homepage | |
| repository | https://github.com/andrewlowndes/multi_stream |
| max_upload_size | |
| id | 903550 |
| size | 27,097 |
Aggregate multiple streams of different types in a single stream with an item type that is a tuple of the incoming stream items.
Option as their corresponding stream may never emit[dependencies]
multi_stream = "0.1.0"
muti_stream macro and pass in stream instances to create a new stream:use async_stream::stream;
use futures::StreamExt;
use multi_stream::multi_stream;
use rand::random;
use std::time::Duration;
use tokio::time::sleep;
#[tokio::main]
async fn main() {
let a = stream! {
sleep(Duration::from_millis(random::<u8>().into())).await;
yield 1;
sleep(Duration::from_millis(random::<u8>().into())).await;
yield 2;
sleep(Duration::from_millis(random::<u8>().into())).await;
yield 3;
};
let b = stream! {
sleep(Duration::from_millis(random::<u8>().into())).await;
yield 4;
sleep(Duration::from_millis(random::<u8>().into())).await;
yield 5;
sleep(Duration::from_millis(random::<u8>().into())).await;
yield 6;
};
multi_stream!(a, b)
.for_each(|(a, b)| async move {
//emitted when any of the streams has a new value
dbg!((a, b));
})
.await;
}