Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

Replace await! macro with await syntax #86

Merged
merged 1 commit into from
May 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ the quote it received to standard out.
### Shakespeare Server

```rust
#![feature(async_await, await_macro)]
#![feature(async_await)]

use std::io;

Expand Down Expand Up @@ -73,14 +73,14 @@ fn main() -> io::Result<()> {

println!("Listening on 127.0.0.1:7878");

while let Some(stream) = await!(incoming.next()) {
while let Some(stream) = incoming.next().await {
let stream = stream?;
let addr = stream.peer_addr()?;

threadpool.spawn(async move {
println!("Accepting stream from: {}", addr);

await!(recite_shakespeare(stream)).unwrap();
recite_shakespeare(stream).await.unwrap();

println!("Closing stream from: {}", addr);
}).unwrap();
Expand All @@ -93,15 +93,15 @@ fn main() -> io::Result<()> {
async fn recite_shakespeare(mut stream: TcpStream) -> io::Result<()> {
//stream.set_keepalive(None);
let &quote = SHAKESPEARE.choose(&mut rand::thread_rng()).unwrap();
await!(stream.write_all(quote))?;
stream.write_all(quote).await?;
Ok(())
}
```

### Shakespeare Client

```rust
#![feature(async_await, await_macro)]
#![feature(async_await)]

use std::io;

Expand All @@ -112,9 +112,9 @@ use romio::TcpStream;

fn main() -> io::Result<()> {
executor::block_on(async {
let mut stream = await!(TcpStream::connect(&"127.0.0.1:7878".parse().unwrap()))?;
let mut stream = TcpStream::connect(&"127.0.0.1:7878".parse().unwrap()).await?;
let mut stdout = AllowStdIo::new(io::stdout());
await!(stream.copy_into(&mut stdout))?;
stream.copy_into(&mut stdout).await?;
Ok(())
})
}
Expand Down
8 changes: 4 additions & 4 deletions examples/echo.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use std::io;

Expand All @@ -18,15 +18,15 @@ fn main() -> io::Result<()> {

println!("Listening on 127.0.0.1:7878");

while let Some(stream) = await!(incoming.next()) {
while let Some(stream) = incoming.next().await {
let stream = stream?;
let addr = stream.peer_addr()?;

threadpool
.spawn(async move {
println!("Accepting stream from: {}", addr);

await!(echo_on(stream)).unwrap();
echo_on(stream).await.unwrap();

println!("Closing stream from: {}", addr);
})
Expand All @@ -39,6 +39,6 @@ fn main() -> io::Result<()> {

async fn echo_on(stream: TcpStream) -> io::Result<()> {
let (mut reader, mut writer) = stream.split();
await!(reader.copy_into(&mut writer))?;
reader.copy_into(&mut writer).await?;
Ok(())
}
6 changes: 3 additions & 3 deletions examples/shakespeare-client.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use std::io;

Expand All @@ -9,9 +9,9 @@ use romio::TcpStream;

fn main() -> io::Result<()> {
executor::block_on(async {
let mut stream = await!(TcpStream::connect(&"127.0.0.1:7878".parse().unwrap()))?;
let mut stream = TcpStream::connect(&"127.0.0.1:7878".parse().unwrap()).await?;
let mut stdout = AllowStdIo::new(io::stdout());
await!(stream.copy_into(&mut stdout))?;
stream.copy_into(&mut stdout).await?;
Ok(())
})
}
8 changes: 4 additions & 4 deletions examples/shakespeare.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use std::io;

Expand Down Expand Up @@ -31,15 +31,15 @@ fn main() -> io::Result<()> {

println!("Listening on 127.0.0.1:7878");

while let Some(stream) = await!(incoming.next()) {
while let Some(stream) = incoming.next().await {
let stream = stream?;
let addr = stream.peer_addr()?;

threadpool
.spawn(async move {
println!("Accepting stream from: {}", addr);

await!(recite_shakespeare(stream)).unwrap();
recite_shakespeare(stream).await.unwrap();

println!("Closing stream from: {}", addr);
})
Expand All @@ -53,6 +53,6 @@ fn main() -> io::Result<()> {
async fn recite_shakespeare(mut stream: TcpStream) -> io::Result<()> {
//stream.set_keepalive(None);
let &quote = SHAKESPEARE.choose(&mut rand::thread_rng()).unwrap();
await!(stream.write_all(quote))?;
stream.write_all(quote).await?;
Ok(())
}
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
//! # Examples
//! __TCP Server__
//! ```rust
//! #![feature(async_await, await_macro)]
//! #![feature(async_await)]
//! use romio::tcp::{TcpListener, TcpStream};
//! use futures::prelude::*;
//!
//! async fn say_hello(mut stream: TcpStream) {
//! await!(stream.write_all(b"Shall I hear more, or shall I speak at this?"));
//! stream.write_all(b"Shall I hear more, or shall I speak at this?").await;
//! }
//!
//! async fn listen() -> Result<(), Box<dyn std::error::Error + 'static>> {
Expand All @@ -32,25 +32,25 @@
//! let mut incoming = listener.incoming();
//!
//! // accept connections and process them serially
//! while let Some(stream) = await!(incoming.next()) {
//! await!(say_hello(stream?));
//! while let Some(stream) = incoming.next().await {
//! say_hello(stream?).await;
//! }
//! Ok(())
//! }
//! ```
//! __TCP Client__
//! ```rust,no_run
//! #![feature(async_await, await_macro)]
//! #![feature(async_await)]
//! use std::error::Error;
//! use futures::prelude::*;
//! use romio::tcp::{TcpListener, TcpStream};
//!
//! async fn receive_sonnet() -> Result<(), Box<dyn Error + 'static>> {
//! let socket_addr = "127.0.0.1:8080".parse()?;
//! let mut buffer = vec![];
//! let mut stream = await!(TcpStream::connect(&socket_addr))?;
//! let mut stream = TcpStream::connect(&socket_addr).await?;
//!
//! await!(stream.read(&mut buffer))?;
//! stream.read(&mut buffer).await?;
//! println!("{:?}", buffer);
//! Ok(())
//! }
Expand Down
16 changes: 8 additions & 8 deletions src/tcp/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ use crate::raw::PollEvented;
/// # Examples
///
/// ```rust,no_run
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// use std::error::Error;
///
/// use romio::tcp::{TcpListener, TcpStream};
/// use futures::prelude::*;
///
/// async fn recite_shakespeare(mut stream: TcpStream) {
/// await!(stream.write_all(b"Shall I hear more, or shall I speak at this?"));
/// stream.write_all(b"Shall I hear more, or shall I speak at this?").await;
/// }
///
/// async fn listen() -> Result<(), Box<dyn Error + 'static>> {
Expand All @@ -43,8 +43,8 @@ use crate::raw::PollEvented;
/// let mut incoming = listener.incoming();
///
/// // accept connections and process them serially
/// while let Some(stream) = await!(incoming.next()) {
/// await!(recite_shakespeare(stream?));
/// while let Some(stream) = incoming.next().await {
/// recite_shakespeare(stream?).await;
/// }
/// Ok(())
/// }
Expand Down Expand Up @@ -125,7 +125,7 @@ impl TcpListener {
/// # Examples
///
/// ```rust,no_run
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// use futures::prelude::*;
/// use romio::tcp::TcpListener;
///
Expand All @@ -135,7 +135,7 @@ impl TcpListener {
/// let mut incoming = listener.incoming();
///
/// // accept connections and process them serially
/// while let Some(stream) = await!(incoming.next()) {
/// while let Some(stream) = incoming.next().await {
/// match stream {
/// Ok(stream) => {
/// println!("new client!");
Expand All @@ -158,7 +158,7 @@ impl TcpListener {
/// # Examples
///
/// ```rust
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// use futures::prelude::*;
/// use romio::tcp::TcpListener;
///
Expand All @@ -181,7 +181,7 @@ impl TcpListener {
/// # Examples
///
/// ```rust,no_run
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// use futures::prelude::*;
/// use romio::tcp::TcpListener;
///
Expand Down
8 changes: 4 additions & 4 deletions src/tcp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
//! # Example
//!
//! ```no_run
//! #![feature(async_await, await_macro)]
//! #![feature(async_await)]
//! use romio::tcp::{TcpListener, TcpStream};
//! use futures::prelude::*;
//!
//! async fn say_hello(mut stream: TcpStream) {
//! await!(stream.write_all(b"Shall I hear more, or shall I speak at this?!"));
//! stream.write_all(b"Shall I hear more, or shall I speak at this?!").await;
//! }
//!
//! async fn listen() -> Result<(), Box<dyn std::error::Error + 'static>> {
Expand All @@ -33,8 +33,8 @@
//! let mut incoming = listener.incoming();
//!
//! // accept connections and process them serially
//! while let Some(stream) = await!(incoming.next()) {
//! await!(say_hello(stream?));
//! while let Some(stream) = incoming.next().await {
//! say_hello(stream?).await;
//! }
//! Ok(())
//! }
Expand Down
Loading