Expand description
Stream for flattening a stream of streams in an unordered fashion,
with ability to specify flow controller.
This is a more generic version of FlattenUnordered
which allows to
control the flow of items from the base stream to the inner streams.
The main use-case is to immediately return an item from the base stream
without adding it to the inner streams bucket.
§Examples
use tokio_stream::StreamExt;
use tokio_stream_util::FlattenUnordered;
#[tokio::main]
async fn main() {
let unordered_stream = tokio_stream::iter(vec![
tokio_stream::iter(vec![1, 2, 3]),
tokio_stream::iter(vec![4, 5, 6]),
tokio_stream::iter(vec![7, 8, 9]),
tokio_stream::iter(vec![10, 11, 12]),
tokio_stream::iter(vec![13, 14, 15]),
tokio_stream::iter(vec![16, 17, 18]),
tokio_stream::iter(vec![19, 20, 21]),
tokio_stream::iter(vec![22, 23, 24]),
tokio_stream::iter(vec![25, 26, 27]),
tokio_stream::iter(vec![28, 29, 30]),
]);
let mut stream = FlattenUnordered::new(unordered_stream, Some(3));
let mut expected_finds = std::collections::HashMap::new();
for i in 1..=30 {
expected_finds.insert(i, false);
}
while let Some(item) = stream.next().await {
assert!(item >= 1 && item <= 30);
*expected_finds.get_mut(&item).unwrap() = true;
}
for (key, found) in expected_finds {
assert!(found, "Item {} was not found in the stream", key);
}
}
Structs§
- Flatten
Unordered With Flow Controller - Stream for flattening a stream of streams in an unordered fashion, with ability to specify flow controller.
Enums§
- Flow
Step - Describes the next flow step.
Traits§
- Flow
Controller - Returns the next flow step based on the received item.
Type Aliases§
- Flatten
Unordered - Stream for flattening a stream of streams in an unordered fashion.