[go: up one dir, main page]

futures 0.3.1

An implementation of futures and streams featuring zero allocations, composability, and iterator-like interfaces.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use futures::executor::block_on;
use futures::stream::{self, StreamExt};

#[test]
fn select() {
    fn select_and_compare(a: Vec<u32>, b: Vec<u32>, expected: Vec<u32>) {
        let a = stream::iter(a);
        let b = stream::iter(b);
        let vec = block_on(stream::select(a, b).collect::<Vec<_>>());
        assert_eq!(vec, expected);
    }

    select_and_compare(vec![1, 2, 3], vec![4, 5, 6], vec![1, 4, 2, 5, 3, 6]);
    select_and_compare(vec![1, 2, 3], vec![4, 5], vec![1, 4, 2, 5, 3]);
    select_and_compare(vec![1, 2], vec![4, 5, 6], vec![1, 4, 2, 5, 6]);
}