1
Fork 0

align async-await.rs and await-macro.rs with one another

This commit is contained in:
Delan Azabani 2019-07-12 13:04:41 +10:00
parent e31911ef8f
commit 1574c2dee2
2 changed files with 20 additions and 3 deletions

View file

@ -3,7 +3,7 @@
// edition:2018 // edition:2018
// aux-build:arc_wake.rs // aux-build:arc_wake.rs
#![feature(async_await)] #![feature(async_await, async_closure)]
extern crate arc_wake; extern crate arc_wake;
@ -70,6 +70,13 @@ fn async_nonmove_block(x: u8) -> impl Future<Output = u8> {
} }
} }
fn async_closure(x: u8) -> impl Future<Output = u8> {
(async move |x: u8| -> u8 {
wake_and_yield_once().await;
x
})(x)
}
async fn async_fn(x: u8) -> u8 { async fn async_fn(x: u8) -> u8 {
wake_and_yield_once().await; wake_and_yield_once().await;
x x
@ -173,6 +180,7 @@ fn main() {
test! { test! {
async_block, async_block,
async_nonmove_block, async_nonmove_block,
async_closure,
async_fn, async_fn,
generic_async_fn, generic_async_fn,
async_fn_with_internal_borrow, async_fn_with_internal_borrow,

View file

@ -134,11 +134,15 @@ trait Bar {
} }
impl Foo { impl Foo {
async fn async_method(x: u8) -> u8 { async fn async_assoc_item(x: u8) -> u8 {
unsafe { unsafe {
await!(unsafe_async_fn(x)) await!(unsafe_async_fn(x))
} }
} }
async unsafe fn async_unsafe_assoc_item(x: u8) -> u8 {
await!(unsafe_async_fn(x))
}
} }
fn test_future_yields_once_then_returns<F, Fut>(f: F) fn test_future_yields_once_then_returns<F, Fut>(f: F)
@ -180,12 +184,17 @@ fn main() {
async_fn, async_fn,
generic_async_fn, generic_async_fn,
async_fn_with_internal_borrow, async_fn_with_internal_borrow,
Foo::async_method, Foo::async_assoc_item,
|x| { |x| {
async move { async move {
unsafe { await!(unsafe_async_fn(x)) } unsafe { await!(unsafe_async_fn(x)) }
} }
}, },
|x| {
async move {
unsafe { await!(Foo::async_unsafe_assoc_item(x)) }
}
},
} }
test_with_borrow! { test_with_borrow! {
async_block_with_borrow_named_lifetime, async_block_with_borrow_named_lifetime,