summaryrefslogtreecommitdiffstats
path: root/third_party/rust/tokio-0.1.22/tests/enumerate.rs
blob: c71b7a24c9f2837b9caa207baa43e962ffe7a727 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
extern crate futures;
extern crate tokio;
extern crate tokio_executor;
extern crate tokio_timer;

use futures::sync::mpsc;
use tokio::util::StreamExt;

#[test]
fn enumerate() {
    use futures::*;

    let (mut tx, rx) = mpsc::channel(1);

    std::thread::spawn(|| {
        for i in 0..5 {
            tx = tx.send(i * 2).wait().unwrap();
        }
    });

    let result = rx.enumerate().collect();
    assert_eq!(
        result.wait(),
        Ok(vec![(0, 0), (1, 2), (2, 4), (3, 6), (4, 8)])
    );
}