Skip to content
This repository was archived by the owner on Oct 30, 2019. It is now read-only.

Commit 3f5324f

Browse files
committed
Replace await! macro with await syntax
1 parent 95414d6 commit 3f5324f

File tree

23 files changed

+94
-93
lines changed

23 files changed

+94
-93
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ asynchronous software.
6969
## Examples
7070
__UDP Echo Server__
7171
```rust
72-
#![feature(async_await, await_macro)]
72+
#![feature(async_await)]
7373

7474
use runtime::net::UdpSocket;
7575

@@ -81,8 +81,8 @@ async fn main() -> std::io::Result<()> {
8181
println!("Listening on {}", socket.local_addr()?);
8282

8383
loop {
84-
let (recv, peer) = await!(socket.recv_from(&mut buf))?;
85-
let sent = await!(socket.send_to(&buf[..recv], &peer))?;
84+
let (recv, peer) = socket.recv_from(&mut buf).await?;
85+
let sent = socket.send_to(&buf[..recv], &peer).await?;
8686
println!("Sent {} out of {} bytes to {}", sent, recv, peer);
8787
}
8888
}

benches/baseline.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(test, async_await, await_macro)]
1+
#![feature(test, async_await)]
22

33
extern crate test;
44

@@ -43,13 +43,13 @@ mod baseline {
4343
let tasks = (0..300)
4444
.map(|_| {
4545
spawn(async move {
46-
await!(Task { depth: 0 });
46+
Task { depth: 0 }.await;
4747
})
4848
})
4949
.collect::<Vec<_>>();
5050

5151
for task in tasks {
52-
await!(task);
52+
task.await;
5353
}
5454
})
5555
});
@@ -62,7 +62,7 @@ mod baseline {
6262
let tasks = (0..25_000).map(|_| spawn(async {})).collect::<Vec<_>>();
6363

6464
for task in tasks {
65-
await!(task);
65+
task.await;
6666
}
6767
})
6868
});
@@ -106,7 +106,7 @@ mod baseline {
106106
.collect::<Vec<_>>();
107107

108108
for task in tasks {
109-
await!(task);
109+
task.await;
110110
}
111111
})
112112
});
@@ -121,7 +121,7 @@ mod baseline {
121121
let (tx, rx) = futures::channel::oneshot::channel();
122122

123123
let fut = async move {
124-
let t = await!(fut);
124+
let t = fut.await;
125125
let _ = tx.send(t);
126126
};
127127

benches/common/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ macro_rules! benchmark_suite {
3131
let tasks = (0..300)
3232
.map(|_| {
3333
runtime::spawn(async {
34-
await!(Task { depth: 0 });
34+
Task { depth: 0 }.await;
3535
})
3636
})
3737
.collect::<Vec<_>>();
3838

3939
for task in tasks {
40-
await!(task);
40+
task.await;
4141
}
4242
}
4343

@@ -48,7 +48,7 @@ macro_rules! benchmark_suite {
4848
.collect::<Vec<_>>();
4949

5050
for task in tasks {
51-
await!(task);
51+
task.await;
5252
}
5353
}
5454

@@ -89,7 +89,7 @@ macro_rules! benchmark_suite {
8989
.collect::<Vec<_>>();
9090

9191
for task in tasks {
92-
await!(task);
92+
task.await;
9393
}
9494
}
9595
};

benches/native.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(test, async_await, await_macro)]
1+
#![feature(test, async_await)]
22
#![warn(rust_2018_idioms)]
33

44
extern crate test;

benches/tokio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(test, async_await, await_macro)]
1+
#![feature(test, async_await)]
22
#![warn(rust_2018_idioms)]
33

44
extern crate test;

examples/guessing.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
//! $ nc localhost 8080
88
//! ```
99
10-
#![feature(async_await, await_macro)]
10+
#![feature(async_await)]
1111

1212
use futures::prelude::*;
1313
use rand::Rng;
@@ -21,14 +21,14 @@ async fn play(stream: TcpStream) -> Result<(), failure::Error> {
2121
let (reader, writer) = &mut stream.split();
2222
let mut buf = vec![0u8; 1024];
2323

24-
await!(writer.write_all(b"Guess the number!\n"))?;
24+
writer.write_all(b"Guess the number!\n").await?;
2525

2626
let secret_number = rand::thread_rng().gen_range(1, 101);
2727

2828
loop {
29-
await!(writer.write_all(b"Please input your guess.\n"))?;
29+
writer.write_all(b"Please input your guess.\n").await?;
3030

31-
let len = await!(reader.read(&mut buf))?;
31+
let len = reader.read(&mut buf).await?;
3232
if len == 0 {
3333
return Ok(());
3434
}
@@ -41,13 +41,13 @@ async fn play(stream: TcpStream) -> Result<(), failure::Error> {
4141
};
4242

4343
let msg = format!("You guessed: {}\n", guess);
44-
await!(writer.write_all(msg.as_bytes()))?;
44+
writer.write_all(msg.as_bytes()).await?;
4545

4646
match guess.cmp(&secret_number) {
47-
Ordering::Less => await!(writer.write_all(b"Too small!\n"))?,
48-
Ordering::Greater => await!(writer.write_all(b"Too big!\n"))?,
47+
Ordering::Less => writer.write_all(b"Too small!\n").await?,
48+
Ordering::Greater => writer.write_all(b"Too big!\n").await?,
4949
Ordering::Equal => {
50-
await!(writer.write_all(b"You win!\n"))?;
50+
writer.write_all(b"You win!\n").await?;
5151
break;
5252
}
5353
}
@@ -62,7 +62,7 @@ async fn main() -> Result<(), failure::Error> {
6262
println!("Listening on {}", &listener.local_addr()?);
6363

6464
let mut incoming = listener.incoming();
65-
while let Some(stream) = await!(incoming.next()) {
65+
while let Some(stream) = incoming.next().await {
6666
runtime::spawn(play(stream?));
6767
}
6868
Ok(())

examples/hello.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#![feature(async_await, await_macro)]
1+
#![feature(async_await)]
22

33
async fn say_hi() {
44
println!("Hello world! 🤖");
55
}
66

77
#[runtime::main]
88
async fn main() {
9-
await!(say_hi());
9+
say_hi().await;
1010
}

examples/tcp-client.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,22 +6,22 @@
66
//! $ cargo run --example tcp-echo
77
//! ```
88
9-
#![feature(async_await, await_macro)]
9+
#![feature(async_await)]
1010

1111
use futures::prelude::*;
1212
use runtime::net::TcpStream;
1313

1414
#[runtime::main]
1515
async fn main() -> Result<(), failure::Error> {
16-
let mut stream = await!(TcpStream::connect("127.0.0.1:8080"))?;
16+
let mut stream = TcpStream::connect("127.0.0.1:8080").await?;
1717
println!("Connected to {}", &stream.peer_addr()?);
1818

1919
let msg = "hello world";
2020
println!("<- {}", msg);
21-
await!(stream.write_all(msg.as_bytes()))?;
21+
stream.write_all(msg.as_bytes()).await?;
2222

2323
let mut buf = vec![0u8; 1024];
24-
await!(stream.read(&mut buf))?;
24+
stream.read(&mut buf).await?;
2525
println!("-> {}\n", String::from_utf8(buf)?);
2626

2727
Ok(())

examples/tcp-echo.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! Run the server and connect to it with `nc 127.0.0.1 8080`.
44
//! The server will wait for you to enter lines of text and then echo them back.
55
6-
#![feature(async_await, await_macro)]
6+
#![feature(async_await)]
77

88
use futures::prelude::*;
99
use runtime::net::TcpListener;
@@ -15,13 +15,13 @@ async fn main() -> std::io::Result<()> {
1515

1616
// accept connections and process them in parallel
1717
let mut incoming = listener.incoming();
18-
while let Some(stream) = await!(incoming.next()) {
18+
while let Some(stream) = incoming.next().await {
1919
runtime::spawn(async move {
2020
let stream = stream?;
2121
println!("Accepting from: {}", stream.peer_addr()?);
2222

2323
let (reader, writer) = &mut stream.split();
24-
await!(reader.copy_into(writer))?;
24+
reader.copy_into(writer).await?;
2525
Ok::<(), std::io::Error>(())
2626
});
2727
}

examples/tcp-proxy.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! A TCP proxy server. Forwards connections from port 8081 to port 8080.
22
3-
#![feature(async_await, await_macro)]
3+
#![feature(async_await)]
4+
#![feature(await_macro)] // TODO: When the next version of futures-preview released, remove this.
45

56
use futures::prelude::*;
67
use futures::try_join;
@@ -13,10 +14,10 @@ async fn main() -> std::io::Result<()> {
1314

1415
// accept connections and process them serially
1516
let mut incoming = listener.incoming();
16-
while let Some(client) = await!(incoming.next()) {
17+
while let Some(client) = incoming.next().await {
1718
let handle = runtime::spawn(async move {
1819
let client = client?;
19-
let server = await!(TcpStream::connect("127.0.0.1:8080"))?;
20+
let server = TcpStream::connect("127.0.0.1:8080").await?;
2021
println!(
2122
"Proxying {} to {}",
2223
client.peer_addr()?,
@@ -32,7 +33,7 @@ async fn main() -> std::io::Result<()> {
3233
Ok::<(), std::io::Error>(())
3334
});
3435

35-
await!(handle)?;
36+
handle.await?;
3637
}
3738
Ok(())
3839
}

examples/udp-client.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(async_await, await_macro)]
1+
#![feature(async_await)]
22

33
//! UDP client.
44
//!
@@ -16,10 +16,10 @@ async fn main() -> std::io::Result<()> {
1616

1717
let msg = "hello world";
1818
println!("<- {}", msg);
19-
await!(socket.send_to(msg.as_bytes(), "127.0.0.1:8080"))?;
19+
socket.send_to(msg.as_bytes(), "127.0.0.1:8080").await?;
2020

2121
let mut buf = vec![0u8; 1024];
22-
await!(socket.recv_from(&mut buf))?;
22+
socket.recv_from(&mut buf).await?;
2323
println!("-> {}\n", String::from_utf8_lossy(&mut buf));
2424

2525
Ok(())

examples/udp-echo.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(async_await, await_macro)]
1+
#![feature(async_await)]
22

33
//! UDP echo server.
44
//!
@@ -17,8 +17,8 @@ async fn main() -> std::io::Result<()> {
1717
println!("Listening on {}", socket.local_addr()?);
1818

1919
loop {
20-
let (recv, peer) = await!(socket.recv_from(&mut buf))?;
21-
let sent = await!(socket.send_to(&buf[..recv], &peer))?;
20+
let (recv, peer) = socket.recv_from(&mut buf).await?;
21+
let sent = socket.send_to(&buf[..recv], &peer).await?;
2222
println!("Sent {} out of {} bytes to {}", sent, recv, peer);
2323
}
2424
}

runtime-attributes/src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
44
#![forbid(unsafe_code, future_incompatible, rust_2018_idioms)]
55
#![deny(missing_debug_implementations, nonstandard_style)]
6-
#![feature(async_await, await_macro)]
6+
#![feature(async_await)]
77
#![recursion_limit = "512"]
88

99
extern crate proc_macro;
@@ -62,7 +62,7 @@ pub fn main(attr: TokenStream, item: TokenStream) -> TokenStream {
6262
}
6363

6464
runtime::raw::enter(#rt, async {
65-
await!(main())
65+
main().await
6666
})
6767
}
6868

@@ -120,13 +120,13 @@ pub fn test(attr: TokenStream, item: TokenStream) -> TokenStream {
120120
/// # Examples
121121
///
122122
/// ```ignore
123-
/// #![feature(async_await, await_macro, test)]
123+
/// #![feature(async_await, test)]
124124
///
125125
/// extern crate test;
126126
///
127127
/// #[runtime::test]
128128
/// async fn spawn_and_await() {
129-
/// await!(runtime::spawn(async {}));
129+
/// runtime::spawn(async {}).await;
130130
/// }
131131
/// ```
132132
#[proc_macro_attribute]

runtime-native/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//! A cross-platform asynchronous [Runtime](https://github.com/rustasync/runtime). See the [Runtime
22
//! documentation](https://docs.rs/runtime) for more details.
33
4-
#![feature(async_await, await_macro)]
4+
#![feature(async_await)]
55
#![deny(unsafe_code)]
66
#![warn(
77
missing_debug_implementations,

runtime-raw/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//! perform IO, then there's no need to bother with any of these types as they will have been
66
//! implemented for you already.
77
8-
#![feature(async_await, await_macro)]
8+
#![feature(async_await)]
99
#![deny(unsafe_code)]
1010
#![warn(
1111
missing_debug_implementations,
@@ -61,7 +61,7 @@ where
6161
let (tx, rx) = futures::channel::oneshot::channel();
6262

6363
let fut = async move {
64-
let t = await!(fut);
64+
let t = fut.await;
6565
let _ = tx.send(t);
6666
};
6767

runtime-tokio/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! [Runtime](https://github.com/rustasync/runtime). See the [Runtime
33
//! documentation](https://docs.rs/runtime) for more details.
44
5-
#![feature(async_await, await_macro)]
5+
#![feature(async_await)]
66
#![warn(
77
missing_debug_implementations,
88
missing_docs,

src/lib.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
//! ## Examples
1717
//! __UDP Echo Server__
1818
//! ```no_run
19-
//! #![feature(async_await, await_macro)]
19+
//! #![feature(async_await)]
2020
//!
2121
//! use runtime::net::UdpSocket;
2222
//!
@@ -28,8 +28,8 @@
2828
//! println!("Listening on {}", socket.local_addr()?);
2929
//!
3030
//! loop {
31-
//! let (recv, peer) = await!(socket.recv_from(&mut buf))?;
32-
//! let sent = await!(socket.send_to(&buf[..recv], &peer))?;
31+
//! let (recv, peer) = socket.recv_from(&mut buf).await?;
32+
//! let sent = socket.send_to(&buf[..recv], &peer).await?;
3333
//! println!("Sent {} out of {} bytes to {}", sent, recv, peer);
3434
//! }
3535
//! }
@@ -85,7 +85,7 @@
8585
//! - [Runtime Tokio](https://docs.rs/runtime-tokio) provides a thread pool, bindings to the OS, and
8686
//! a work-stealing scheduler.
8787
88-
#![feature(async_await, await_macro)]
88+
#![feature(async_await)]
8989
#![deny(unsafe_code)]
9090
#![warn(
9191
missing_debug_implementations,

0 commit comments

Comments
 (0)