mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-03 00:00:05 +02:00
Remove the Reactor::run method (#58)
This commit removes the `Reactor::run` method which has previously been used to execute futures and turn the reactor at the same time. The tests/examples made heavy usage of this method but they have now all temporarily moved to `wait()` until the futures dependency is upgraded. In the meantime this'll allow us to further trim down the `Reactor` APIs to their final state.
This commit is contained in:
committed by
Carl Lerche
parent
32f2750c2d
commit
a577bfc033
+9
-12
@@ -13,7 +13,7 @@ use futures::{Future, Stream, Sink};
|
||||
use futures::future::Executor;
|
||||
use futures_cpupool::CpuPool;
|
||||
use tokio::net::{TcpListener, TcpStream};
|
||||
use tokio::reactor::Reactor;
|
||||
use tokio::reactor::Handle;
|
||||
use tokio_io::codec::{Encoder, Decoder};
|
||||
use tokio_io::io::{write_all, read};
|
||||
use tokio_io::AsyncRead;
|
||||
@@ -55,10 +55,8 @@ impl Encoder for LineCodec {
|
||||
fn echo() {
|
||||
drop(env_logger::init());
|
||||
|
||||
let mut core = Reactor::new().unwrap();
|
||||
let handle = core.handle();
|
||||
|
||||
let pool = CpuPool::new(1);
|
||||
let handle = Handle::default();
|
||||
|
||||
let listener = TcpListener::bind(&"127.0.0.1:0".parse().unwrap(), &handle).unwrap();
|
||||
let addr = listener.local_addr().unwrap();
|
||||
@@ -69,24 +67,23 @@ fn echo() {
|
||||
Ok(())
|
||||
});
|
||||
|
||||
let handle = core.handle();
|
||||
pool.execute(srv.map_err(|e| panic!("srv error: {}", e))).unwrap();
|
||||
|
||||
let client = TcpStream::connect(&addr, &handle);
|
||||
let client = core.run(client).unwrap();
|
||||
let (client, _) = core.run(write_all(client, b"a\n")).unwrap();
|
||||
let (client, buf, amt) = core.run(read(client, vec![0; 1024])).unwrap();
|
||||
let client = client.wait().unwrap();
|
||||
let (client, _) = write_all(client, b"a\n").wait().unwrap();
|
||||
let (client, buf, amt) = read(client, vec![0; 1024]).wait().unwrap();
|
||||
assert_eq!(amt, 2);
|
||||
assert_eq!(&buf[..2], b"a\n");
|
||||
|
||||
let (client, _) = core.run(write_all(client, b"\n")).unwrap();
|
||||
let (client, buf, amt) = core.run(read(client, buf)).unwrap();
|
||||
let (client, _) = write_all(client, b"\n").wait().unwrap();
|
||||
let (client, buf, amt) = read(client, buf).wait().unwrap();
|
||||
assert_eq!(amt, 1);
|
||||
assert_eq!(&buf[..1], b"\n");
|
||||
|
||||
let (client, _) = core.run(write_all(client, b"b")).unwrap();
|
||||
let (client, _) = write_all(client, b"b").wait().unwrap();
|
||||
client.shutdown(Shutdown::Write).unwrap();
|
||||
let (_client, buf, amt) = core.run(read(client, buf)).unwrap();
|
||||
let (_client, buf, amt) = read(client, buf).wait().unwrap();
|
||||
assert_eq!(amt, 1);
|
||||
assert_eq!(&buf[..1], b"b");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user