diff options
Diffstat (limited to 'async-await')
-rw-r--r-- | async-await/Cargo.toml | 20 | ||||
-rw-r--r-- | async-await/src/chat.rs | 14 | ||||
-rw-r--r-- | async-await/src/echo_client.rs | 10 | ||||
-rw-r--r-- | async-await/src/echo_server.rs | 8 | ||||
-rw-r--r-- | async-await/src/hyper.rs | 6 | ||||
-rw-r--r-- | async-await/tests/macros.rs | 4 |
6 files changed, 22 insertions, 40 deletions
diff --git a/async-await/Cargo.toml b/async-await/Cargo.toml index e605da60..52933b28 100644 --- a/async-await/Cargo.toml +++ b/async-await/Cargo.toml @@ -25,25 +25,7 @@ name = "hyper" path = "src/hyper.rs" [dependencies] -tokio = { version = "0.1.18", features = ["async-await-preview"] } +tokio = { version = "0.2.0", features = ["async-await-preview"], path = "../tokio" } futures = "0.1.23" bytes = "0.4.9" hyper = "0.12.8" - -# Avoid using crates.io for Tokio dependencies -[patch.crates-io] -tokio = { path = "../tokio" } -tokio-codec = { path = "../tokio-codec" } -tokio-current-thread = { path = "../tokio-current-thread" } -tokio-executor = { path = "../tokio-executor" } -tokio-fs = { path = "../tokio-fs" } -tokio-futures = { path = "../tokio-futures" } -tokio-io = { path = "../tokio-io" } -tokio-reactor = { path = "../tokio-reactor" } -tokio-signal = { path = "../tokio-signal" } -tokio-tcp = { path = "../tokio-tcp" } -tokio-threadpool = { path = "../tokio-threadpool" } -tokio-timer = { path = "../tokio-timer" } -tokio-tls = { path = "../tokio-tls" } -tokio-udp = { path = "../tokio-udp" } -tokio-uds = { path = "../tokio-uds" } diff --git a/async-await/src/chat.rs b/async-await/src/chat.rs index d0576f52..d3a0c992 100644 --- a/async-await/src/chat.rs +++ b/async-await/src/chat.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::codec::{LinesCodec, Decoder}; use tokio::net::{TcpListener, TcpStream}; use tokio::prelude::*; @@ -33,7 +33,7 @@ async fn process(stream: TcpStream, state: Arc<Mutex<Shared>>) -> io::Result<()> let mut lines = LinesCodec::new().framed(stream); // Extract the peer's name - let name = match await!(lines.next()) { + let name = match async_wait!(lines.next()) { Some(name) => name?, None => { // Disconnected early @@ -56,15 +56,15 @@ async fn process(stream: TcpStream, state: Arc<Mutex<Shared>>) -> io::Result<()> // Spawn a task that receives all lines broadcasted to us from other peers // and writes it to the client. tokio::spawn_async(async move { - while let Some(line) = await!(rx.next()) { + while let Some(line) = async_wait!(rx.next()) { let line = line.unwrap(); - await!(lines_tx.send_async(line)).unwrap(); + async_wait!(lines_tx.send_async(line)).unwrap(); } }); // Use the current task to read lines from the socket and broadcast them to // other peers. - while let Some(message) = await!(lines_rx.next()) { + while let Some(message) = async_wait!(lines_rx.next()) { // TODO: Error handling let message = message.unwrap(); @@ -113,7 +113,7 @@ async fn main() { // Start the Tokio runtime. let mut incoming = listener.incoming(); - while let Some(stream) = await!(incoming.next()) { + while let Some(stream) = async_wait!(incoming.next()) { let stream = match stream { Ok(stream) => stream, Err(_) => continue, @@ -122,7 +122,7 @@ async fn main() { let state = state.clone(); tokio::spawn_async(async move { - if let Err(_) = await!(process(stream, state)) { + if let Err(_) = async_wait!(process(stream, state)) { eprintln!("failed to process connection"); } }); diff --git a/async-await/src/echo_client.rs b/async-await/src/echo_client.rs index 7cab4932..302b7ea2 100644 --- a/async-await/src/echo_client.rs +++ b/async-await/src/echo_client.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::net::TcpStream; use tokio::prelude::*; @@ -14,7 +14,7 @@ const MESSAGES: &[&str] = &[ ]; async fn run_client(addr: &SocketAddr) -> io::Result<()> { - let mut stream = await!(TcpStream::connect(addr))?; + let mut stream = async_wait!(TcpStream::connect(addr))?; // Buffer to read into let mut buf = [0; 128]; @@ -23,10 +23,10 @@ async fn run_client(addr: &SocketAddr) -> io::Result<()> { println!(" > write = {:?}", msg); // Write the message to the server - await!(stream.write_all_async(msg.as_bytes()))?; + async_wait!(stream.write_all_async(msg.as_bytes()))?; // Read the message back from the server - await!(stream.read_exact_async(&mut buf[..msg.len()]))?; + async_wait!(stream.read_exact_async(&mut buf[..msg.len()]))?; assert_eq!(&buf[..msg.len()], msg.as_bytes()); } @@ -43,7 +43,7 @@ async fn main() { // Connect to the echo serveer - match await!(run_client(&addr)) { + match async_wait!(run_client(&addr)) { Ok(_) => println!("done."), Err(e) => eprintln!("echo client failed; error = {:?}", e), } diff --git a/async-await/src/echo_server.rs b/async-await/src/echo_server.rs index d282ad6b..63e10e31 100644 --- a/async-await/src/echo_server.rs +++ b/async-await/src/echo_server.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::net::{TcpListener, TcpStream}; use tokio::prelude::*; @@ -11,11 +11,11 @@ fn handle(mut stream: TcpStream) { let mut buf = [0; 1024]; loop { - match await!(stream.read_async(&mut buf)).unwrap() { + match async_wait!(stream.read_async(&mut buf)).unwrap() { 0 => break, // Socket closed n => { // Send the data back - await!(stream.write_all_async(&buf[0..n])).unwrap(); + async_wait!(stream.write_all_async(&buf[0..n])).unwrap(); } } } @@ -35,7 +35,7 @@ async fn main() { let mut incoming = listener.incoming(); - while let Some(stream) = await!(incoming.next()) { + while let Some(stream) = async_wait!(incoming.next()) { let stream = stream.unwrap(); handle(stream); } diff --git a/async-await/src/hyper.rs b/async-await/src/hyper.rs index c86481b4..37332ee4 100644 --- a/async-await/src/hyper.rs +++ b/async-await/src/hyper.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::prelude::*; use hyper::Client; @@ -13,7 +13,7 @@ async fn main() { let uri = "http://httpbin.org/ip".parse().unwrap(); - let response = await!({ + let response = async_wait!({ client.get(uri) .timeout(Duration::from_secs(10)) }).unwrap(); @@ -22,7 +22,7 @@ async fn main() { let mut body = response.into_body(); - while let Some(chunk) = await!(body.next()) { + while let Some(chunk) = async_wait!(body.next()) { let chunk = chunk.unwrap(); println!("chunk = {}", str::from_utf8(&chunk[..]).unwrap()); } diff --git a/async-await/tests/macros.rs b/async-await/tests/macros.rs index 285e5538..1fcbf77b 100644 --- a/async-await/tests/macros.rs +++ b/async-await/tests/macros.rs @@ -1,6 +1,6 @@ #![feature(await_macro, async_await)] -use tokio::await; +use tokio::async_wait; use tokio::timer::Delay; use std::time::{Duration, Instant}; @@ -18,5 +18,5 @@ async fn fail_no_async() { #[tokio::test] async fn use_timer() { let when = Instant::now() + Duration::from_millis(10); - await!(Delay::new(when)); + async_wait!(Delay::new(when)); } |