2016-08-31 00:19:29 -07:00
|
|
|
extern crate tokio_core;
|
|
|
|
|
extern crate env_logger;
|
|
|
|
|
extern crate futures;
|
|
|
|
|
|
|
|
|
|
use futures::Future;
|
2016-09-02 11:07:52 -07:00
|
|
|
use tokio_core::reactor::Core;
|
2016-08-31 00:19:29 -07:00
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn simple() {
|
|
|
|
|
drop(env_logger::init());
|
2016-09-02 11:07:52 -07:00
|
|
|
let mut lp = Core::new().unwrap();
|
2016-08-31 00:19:29 -07:00
|
|
|
|
|
|
|
|
let (tx1, rx1) = futures::oneshot();
|
|
|
|
|
let (tx2, rx2) = futures::oneshot();
|
2016-09-07 16:11:19 -07:00
|
|
|
lp.handle().spawn(futures::lazy(|| {
|
2016-08-31 00:19:29 -07:00
|
|
|
tx1.complete(1);
|
|
|
|
|
Ok(())
|
|
|
|
|
}));
|
2016-09-07 16:11:19 -07:00
|
|
|
lp.remote().spawn(|_| {
|
2016-08-31 00:19:29 -07:00
|
|
|
futures::lazy(|| {
|
|
|
|
|
tx2.complete(2);
|
|
|
|
|
Ok(())
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
assert_eq!(lp.run(rx1.join(rx2)).unwrap(), (1, 2));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
|
fn spawn_in_poll() {
|
|
|
|
|
drop(env_logger::init());
|
2016-09-02 11:07:52 -07:00
|
|
|
let mut lp = Core::new().unwrap();
|
2016-08-31 00:19:29 -07:00
|
|
|
|
|
|
|
|
let (tx1, rx1) = futures::oneshot();
|
|
|
|
|
let (tx2, rx2) = futures::oneshot();
|
2016-09-07 16:11:19 -07:00
|
|
|
let remote = lp.remote();
|
|
|
|
|
lp.handle().spawn(futures::lazy(move || {
|
2016-08-31 00:19:29 -07:00
|
|
|
tx1.complete(1);
|
2016-09-07 16:11:19 -07:00
|
|
|
remote.spawn(|_| {
|
2016-08-31 00:19:29 -07:00
|
|
|
futures::lazy(|| {
|
|
|
|
|
tx2.complete(2);
|
|
|
|
|
Ok(())
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
Ok(())
|
|
|
|
|
}));
|
|
|
|
|
|
|
|
|
|
assert_eq!(lp.run(rx1.join(rx2)).unwrap(), (1, 2));
|
|
|
|
|
}
|