summaryrefslogtreecommitdiffstats
path: root/third_party/rust/futures-0.1.31/tests/fuse.rs
blob: 177d914e19a06a7e245513c5278dc994338c4caa (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
27
28
29
30
31
32
33
34
35
36
37
38
39
extern crate futures;

use futures::prelude::*;
use futures::future::ok;
use futures::executor;

mod support;
use support::*;

#[test]
fn fuse() {
    let mut future = executor::spawn(ok::<i32, u32>(2).fuse());
    assert!(future.poll_future_notify(&notify_panic(), 0).unwrap().is_ready());
    assert!(future.poll_future_notify(&notify_panic(), 0).unwrap().is_not_ready());
}

#[test]
fn fuse_is_done() {
    use futures::future::{Fuse, FutureResult};

    struct Wrapped(Fuse<FutureResult<i32, u32>>);

    impl Future for Wrapped {
        type Item = ();
        type Error = ();

        fn poll(&mut self) -> Poll<(), ()> {
            assert!(!self.0.is_done());
            assert_eq!(self.0.poll().unwrap(), Async::Ready(2));
            assert!(self.0.is_done());
            assert_eq!(self.0.poll().unwrap(), Async::NotReady);
            assert!(self.0.is_done());
            
            Ok(Async::Ready(()))            
        }
    }

    assert!(Wrapped(ok::<i32, u32>(2).fuse()).wait().is_ok());
}