#branch #stream #future #fork

gabelung

Branch an asynchronous stream of cloneable items into two

5 releases

0.2.4 Nov 6, 2020
0.2.3 May 28, 2020
0.2.2 May 27, 2020
0.2.1 May 26, 2020
0.2.0 May 26, 2020

#1041 in Asynchronous

MIT license

17KB
331 lines

crates.io

gabelung

Branch an asynchronous stream into two, pushing all items to both halves.

The resulting branches can be polled independently from each other and will receive all items from the underlying stream (which must be Clone).

As long as both halves are alive, one half will never outpace the other by more than a fixed number of items.

The goal of this library is to obsolete itself by integration with futures-rs (pending issue). It does not depend on executor features and thus is runtime agnostic. It is verified to work on both async_std and tokio.

Example

use futures::{stream, prelude::*};

let (mut left, mut right) = gabelung::new(stream::repeat(1u8));

assert_eq!(left.next().await, Some(1u8));
assert_eq!(right.next().await, Some(1u8));

License

MIT


lib.rs:

Branch an asynchronous stream into two, pushing all items to both halves.

The resulting branches can be polled independently from each other and will receive all items from the underlying stream (which must be Clone).

As long as both halves are alive, one half will never outpace the other by more than a fixed number of items.

This library is runtime agnostic. It is verified to work on both async_std and tokio.

Example

use futures::{stream, prelude::*};

let (mut left, mut right) = gabelung::new(stream::repeat(1u8));

assert_eq!(left.next().await, Some(1u8));
assert_eq!(right.next().await, Some(1u8));

Dependencies

~1–1.5MB
~27K SLoC