2 releases
0.1.1 | Apr 13, 2019 |
---|---|
0.1.0 | Apr 13, 2019 |
#24 in #output-stream
11KB
248 lines
weighted-select
Usage:
use weighted_select::{self, IncompleteSelect};
let select = weighted_select::new()
.append(fetch_from_a, 5)
.append(fetch_from_b, 2)
.append(fetch_from_c, 3)
.build();
It produces a stream that combines three underlying streams (fetch_from_*
) and polls them according to their weights (5
, 2
, 3
). Each stream will be polled at most weight
times consecutively.
lib.rs
:
An adapter for merging the output of several streams with priority.
The merged stream produces items from either of the underlying streams as they become available, and the streams are polled according to priority.
Example:
use weighted_select::{self, IncompleteSelect};
let select = weighted_select::new()
.append(iter_ok::<_, ()>(vec![1u32, 1]), 1)
.append(iter_ok(vec![2, 2, 2, 2, 2]), 3)
.append(iter_ok(vec![3, 3, 3, 3]), 2)
.build();
let actual = select.wait().collect::<Result<Vec<_>, _>>().unwrap();
assert_eq!(actual, vec![1, 2, 2, 2, 3, 3, 1, 2, 2, 3, 3]);
Dependencies
~54KB