Skip to content

Replace await! macro with await syntax #1583

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 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
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ matrix:

# When updating this, the reminder to update the minimum required version in README.md.
- name: cargo test (minimum required version)
rust: nightly-2019-04-30
rust: nightly-2019-05-09

- name: cargo clippy
rust: nightly
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Now, you can use futures-rs:
use futures::future::Future; // Note: It's not `futures_preview`
```

The current version of futures-rs requires Rust nightly 2019-04-30 or later.
The current version of futures-rs requires Rust nightly 2019-05-09 or later.

### Feature `std`

Expand Down
4 changes: 2 additions & 2 deletions futures-channel/tests/channel.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use futures::channel::mpsc;
use futures::executor::block_on;
Expand Down Expand Up @@ -28,7 +28,7 @@ fn sequence() {

async fn send_sequence(n: u32, mut sender: mpsc::Sender<u32>) {
for x in 0..n {
await!(sender.send(n - x)).unwrap();
sender.send(n - x).await.unwrap();
}
}

Expand Down
6 changes: 3 additions & 3 deletions futures-channel/tests/mpsc.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(async_await, await_macro)]
#![feature(async_await)]

use futures::channel::{mpsc, oneshot};
use futures::executor::{block_on, block_on_stream};
Expand Down Expand Up @@ -357,7 +357,7 @@ fn stress_drop_sender() {

async fn send_one_two_three(mut tx: mpsc::Sender<i32>) {
for i in 1..=3 {
await!(tx.send(i)).unwrap();
tx.send(i).await.unwrap();
}
}

Expand Down Expand Up @@ -403,7 +403,7 @@ fn stress_close_receiver() {

async fn stress_poll_ready_sender(mut sender: mpsc::Sender<u32>, count: u32) {
for i in (1..=count).rev() {
await!(sender.send(i)).unwrap();
sender.send(i).await.unwrap();
}
}

Expand Down
2 changes: 1 addition & 1 deletion futures-select-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub fn select(input: TokenStream) -> TokenStream {
}
} else {
quote! {
match r#await!(#futures_crate::future::poll_fn(__poll_fn)) {
match #futures_crate::future::poll_fn(__poll_fn).await {
#branches
}
}
Expand Down
16 changes: 8 additions & 8 deletions futures-util/src/async_await/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/// Polls multiple futures simultaneously, returning a tuple
/// of all results once complete.
///
/// While `join!(a, b)` is similar to `(await!(a), await!(b))`,
/// While `join!(a, b)` is similar to `(a.await, b.await)`,
/// `join!` polls both futures concurrently and therefore is more efficent.
///
/// This macro is only usable inside of async functions, closures, and blocks.
Expand All @@ -13,7 +13,7 @@
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::{join, future};
///
Expand All @@ -31,7 +31,7 @@ macro_rules! join {
// is no longer accessible by the end user.
let mut $fut = $crate::future::maybe_done($fut);
)*
await!($crate::future::poll_fn(move |cx| {
$crate::future::poll_fn(move |cx| {
let mut all_done = true;
$(
all_done &= $crate::core_reexport::future::Future::poll(
Expand All @@ -44,7 +44,7 @@ macro_rules! join {
} else {
$crate::core_reexport::task::Poll::Pending
}
}))
}).await
} }
}

Expand All @@ -64,7 +64,7 @@ macro_rules! join {
/// `Ok` of a tuple of the values:
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::{try_join, future};
///
Expand All @@ -79,7 +79,7 @@ macro_rules! join {
/// that error:
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::{try_join, future};
///
Expand All @@ -98,7 +98,7 @@ macro_rules! try_join {
let mut $fut = $crate::future::maybe_done($fut);
)*

let res: $crate::core_reexport::result::Result<_, _> = await!($crate::future::poll_fn(move |cx| {
let res: $crate::core_reexport::result::Result<_, _> = $crate::future::poll_fn(move |cx| {
let mut all_done = true;
$(
if $crate::core_reexport::future::Future::poll(
Expand Down Expand Up @@ -126,7 +126,7 @@ macro_rules! try_join {
} else {
$crate::core_reexport::task::Poll::Pending
}
}));
}).await;

res
} }
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/async_await/pending.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use futures_core::task::{Context, Poll};
#[macro_export]
macro_rules! pending {
() => {
await!($crate::async_await::pending_once())
$crate::async_await::pending_once().await
}
}

Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/async_await/poll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use futures_core::task::{Context, Poll};
#[macro_export]
macro_rules! poll {
($x:expr) => {
await!($crate::async_await::poll($x))
$crate::async_await::poll($x).await
}
}

Expand Down
6 changes: 3 additions & 3 deletions futures-util/src/async_await/select_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ macro_rules! document_select_macro {
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future::{self, FutureExt};
/// use futures::select;
Expand All @@ -42,7 +42,7 @@ macro_rules! document_select_macro {
/// ```
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future::{self, FutureExt};
/// use futures::stream::{self, StreamExt};
Expand All @@ -64,7 +64,7 @@ macro_rules! document_select_macro {
/// the case where all futures have completed.
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future::{self, FutureExt};
/// use futures::select;
Expand Down
26 changes: 13 additions & 13 deletions futures-util/src/compat/compat01as03.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ pub trait Future01CompatExt: Future01 {
/// [`Future<Output = Result<T, E>>`](futures_core::future::Future).
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// # // TODO: These should be all using `futures::compat`, but that runs up against Cargo
/// # // feature issues
/// use futures_util::compat::Future01CompatExt;
///
/// let future = futures_01::future::ok::<u32, ()>(1);
/// assert_eq!(await!(future.compat()), Ok(1));
/// assert_eq!(future.compat().await, Ok(1));
/// # });
/// ```
fn compat(self) -> Compat01As03<Self>
Expand All @@ -79,15 +79,15 @@ pub trait Stream01CompatExt: Stream01 {
/// [`Stream<Item = Result<T, E>>`](futures_core::stream::Stream).
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::stream::StreamExt;
/// use futures_util::compat::Stream01CompatExt;
///
/// let stream = futures_01::stream::once::<u32, ()>(Ok(1));
/// let mut stream = stream.compat();
/// assert_eq!(await!(stream.next()), Some(Ok(1)));
/// assert_eq!(await!(stream.next()), None);
/// assert_eq!(stream.next().await, Some(Ok(1)));
/// assert_eq!(stream.next().await, None);
/// # });
/// ```
fn compat(self) -> Compat01As03<Self>
Expand All @@ -107,18 +107,18 @@ pub trait Sink01CompatExt: Sink01 {
/// [`Sink<SinkItem = T, SinkError = E>`](futures_sink::sink::Sink).
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::{sink::SinkExt, stream::StreamExt};
/// use futures_util::compat::{Stream01CompatExt, Sink01CompatExt};
///
/// let (tx, rx) = futures_01::unsync::mpsc::channel(1);
/// let (mut tx, mut rx) = (tx.sink_compat(), rx.compat());
///
/// await!(tx.send(1)).unwrap();
/// tx.send(1).await.unwrap();
/// drop(tx);
/// assert_eq!(await!(rx.next()), Some(Ok(1)));
/// assert_eq!(await!(rx.next()), None);
/// assert_eq!(rx.next().await, Some(Ok(1)));
/// assert_eq!(rx.next().await, None);
/// # });
/// ```
fn sink_compat(self) -> Compat01As03Sink<Self, Self::SinkItem>
Expand Down Expand Up @@ -356,7 +356,7 @@ mod io {
/// [`AsyncRead`](futures_io::AsyncRead).
///
/// ```
/// #![feature(async_await, await_macro, impl_trait_in_bindings)]
/// #![feature(async_await, impl_trait_in_bindings)]
/// # futures::executor::block_on(async {
/// use futures::io::AsyncReadExt;
/// use futures_util::compat::AsyncRead01CompatExt;
Expand All @@ -366,7 +366,7 @@ mod io {
/// let mut reader: impl futures::io::AsyncRead + Unpin = reader.compat();
///
/// let mut output = Vec::with_capacity(12);
/// await!(reader.read_to_end(&mut output)).unwrap();
/// reader.read_to_end(&mut output).await.unwrap();
/// assert_eq!(output, input);
/// # });
/// ```
Expand All @@ -385,7 +385,7 @@ mod io {
/// [`AsyncWrite`](futures_io::AsyncWrite).
///
/// ```
/// #![feature(async_await, await_macro, impl_trait_in_bindings)]
/// #![feature(async_await, impl_trait_in_bindings)]
/// # futures::executor::block_on(async {
/// use futures::io::AsyncWriteExt;
/// use futures_util::compat::AsyncWrite01CompatExt;
Expand All @@ -394,7 +394,7 @@ mod io {
/// let mut cursor = std::io::Cursor::new(Vec::with_capacity(12));
///
/// let mut writer = (&mut cursor).compat();
/// await!(writer.write_all(input)).unwrap();
/// writer.write_all(input).await.unwrap();
///
/// assert_eq!(cursor.into_inner(), input);
/// # });
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/compat/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub trait Executor01CompatExt: Executor01<Executor01Future> +
/// futures 0.3 [`Spawn`](futures_core::task::Spawn).
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// use futures::Future;
/// use futures::task::SpawnExt;
/// use futures::future::{FutureExt, TryFutureExt};
Expand Down
4 changes: 2 additions & 2 deletions futures-util/src/future/empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ impl<T> FusedFuture for Empty<T> {
/// # Examples
///
/// ```ignore
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future;
///
/// let future = future::empty();
/// let () = await!(future);
/// let () = future.await;
/// unreachable!();
/// # });
/// ```
Expand Down
2 changes: 1 addition & 1 deletion futures-util/src/future/fuse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl<Fut: Future> Fuse<Fut> {
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro, futures_api)]
/// #![feature(async_await, futures_api)]
/// # futures::executor::block_on(async {
/// use futures::channel::mpsc;
/// use futures::future::{Fuse, FusedFuture, FutureExt};
Expand Down
16 changes: 8 additions & 8 deletions futures-util/src/future/join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,15 @@ generate! {
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future;
///
/// let a = future::ready(1);
/// let b = future::ready(2);
/// let pair = future::join(a, b);
///
/// assert_eq!(await!(pair), (1, 2));
/// assert_eq!(pair.await, (1, 2));
/// # });
/// ```
pub fn join<Fut1, Fut2>(future1: Fut1, future2: Fut2) -> Join<Fut1, Fut2>
Expand All @@ -115,7 +115,7 @@ where
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future;
///
Expand All @@ -124,7 +124,7 @@ where
/// let c = future::ready(3);
/// let tuple = future::join3(a, b, c);
///
/// assert_eq!(await!(tuple), (1, 2, 3));
/// assert_eq!(tuple.await, (1, 2, 3));
/// # });
/// ```
pub fn join3<Fut1, Fut2, Fut3>(
Expand All @@ -145,7 +145,7 @@ where
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future;
///
Expand All @@ -155,7 +155,7 @@ where
/// let d = future::ready(4);
/// let tuple = future::join4(a, b, c, d);
///
/// assert_eq!(await!(tuple), (1, 2, 3, 4));
/// assert_eq!(tuple.await, (1, 2, 3, 4));
/// # });
/// ```
pub fn join4<Fut1, Fut2, Fut3, Fut4>(
Expand All @@ -179,7 +179,7 @@ where
/// # Examples
///
/// ```
/// #![feature(async_await, await_macro)]
/// #![feature(async_await)]
/// # futures::executor::block_on(async {
/// use futures::future;
///
Expand All @@ -190,7 +190,7 @@ where
/// let e = future::ready(5);
/// let tuple = future::join5(a, b, c, d, e);
///
/// assert_eq!(await!(tuple), (1, 2, 3, 4, 5));
/// assert_eq!(tuple.await, (1, 2, 3, 4, 5));
/// # });
/// ```
pub fn join5<Fut1, Fut2, Fut3, Fut4, Fut5>(
Expand Down
Loading