Update to futures master

* Remove `LoopData` as it's no longer necessary
* Add `LoopHandle::spawn` to spawn new futures onto an event loop
* Add `LoopData::spawn` to also spawn new futures onto an event loop
* Rejigger the implementation of the event loop a bit (make a slab of futures),
  but otherwise everything else is pretty constant.
This commit is contained in:
Alex Crichton
2016-08-31 19:00:42 -07:00
parent 440a813c5a
commit 330ab823b0
8 changed files with 343 additions and 502 deletions
+49
View File
@@ -0,0 +1,49 @@
extern crate tokio_core;
extern crate env_logger;
extern crate futures;
use futures::Future;
use tokio_core::Loop;
#[test]
fn simple() {
drop(env_logger::init());
let mut lp = Loop::new().unwrap();
let (tx1, rx1) = futures::oneshot();
let (tx2, rx2) = futures::oneshot();
lp.pin().spawn(futures::lazy(|| {
tx1.complete(1);
Ok(())
}));
lp.handle().spawn(|_| {
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());
let mut lp = Loop::new().unwrap();
let (tx1, rx1) = futures::oneshot();
let (tx2, rx2) = futures::oneshot();
let handle = lp.handle();
lp.pin().spawn(futures::lazy(move || {
tx1.complete(1);
handle.spawn(|_| {
futures::lazy(|| {
tx2.complete(2);
Ok(())
})
});
Ok(())
}));
assert_eq!(lp.run(rx1.join(rx2)).unwrap(), (1, 2));
}