mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00

Renamed APIs * Loop => reactor::Core * LoopHandle => reactor::Handle * LoopPin => reactor::Pinned * TcpStream => net::TcpStream * TcpListener => net::TcpListener * UdpSocket => net::UdpSocket * Sender => channel::Sender * Receiver => channel::Receiver * Timeout => reactor::Timeout * ReadinessStream => reactor::PollEvented * All `LoopHandle` methods to construct objects are now free functions on the associated types, e.g. `LoopHandle::tcp_listen` is now `TcpListener::bind` * All APIs taking a `Handle` now take a `Handle` as the last argument * All future-returning APIs now return concrete types instead of trait objects Added APIs * io::Io trait -- Read + Write + ability to poll Removed without replacement: * AddSource * AddTimeout * IoToken * TimeoutToken Closes #3 Closes #6
50 lines
1.0 KiB
Rust
50 lines
1.0 KiB
Rust
extern crate tokio_core;
|
|
extern crate env_logger;
|
|
extern crate futures;
|
|
|
|
use futures::Future;
|
|
use tokio_core::reactor::Core;
|
|
|
|
#[test]
|
|
fn simple() {
|
|
drop(env_logger::init());
|
|
let mut lp = Core::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 = Core::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));
|
|
}
|