mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +02:00
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:
@@ -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));
|
||||
}
|
||||
Reference in New Issue
Block a user