Crates.io | stream-broadcast |
lib.rs | stream-broadcast |
version | 0.3.0 |
source | src |
created_at | 2023-07-19 18:39:29.981148 |
updated_at | 2024-02-28 08:49:11.917919 |
description | Runtime independent broadcast, which only polls it's underlying stream if no pending data is available |
homepage | |
repository | https://github.com/mineichen/stream-broadcast-rs |
max_upload_size | |
id | 920645 |
size | 17,889 |
Runtime independent broadcast, which only polls it's underlying stream if no pending data is available.
use futures::StreamExt;
use stream_broadcast::StreamBroadcastExt;
#[tokio::main]
async fn main() {
let broadcast = futures::stream::iter('a'..='d').fuse().broadcast(3);
let broadcast2 = broadcast.clone();
assert_eq!(4, broadcast.count().await);
// Letter 'a' wasn't available anymore due to `broadcast(3)`, which limits the buffer to 3 items
// Left side of tuple represents number of missed items
assert_eq!(vec![(1, 'b'), (0, 'c'), (0, 'd')], broadcast2.collect::<Vec<_>>().await);
}
Uses #![forbid(unsafe_code)]
Caches the entire stream from start, which is not practical for big datasets. This crate streams from the same position where the clone-origin is currently at
shared_stream never skips an entry. This library only provides information about missing data
High risk of leaking memory
stream.count()