remove implicit .await from core::future::join
This commit is contained in:
parent
d07cef22b0
commit
a8c9314100
2 changed files with 64 additions and 53 deletions
|
@ -22,7 +22,7 @@ use crate::task::Poll;
|
||||||
/// async fn two() -> usize { 2 }
|
/// async fn two() -> usize { 2 }
|
||||||
///
|
///
|
||||||
/// # let _ = async {
|
/// # let _ = async {
|
||||||
/// let x = join!(one(), two());
|
/// let x = join!(one(), two()).await;
|
||||||
/// assert_eq!(x, (1, 2));
|
/// assert_eq!(x, (1, 2));
|
||||||
/// # };
|
/// # };
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -39,7 +39,7 @@ use crate::task::Poll;
|
||||||
/// async fn three() -> usize { 3 }
|
/// async fn three() -> usize { 3 }
|
||||||
///
|
///
|
||||||
/// # let _ = async {
|
/// # let _ = async {
|
||||||
/// let x = join!(one(), two(), three());
|
/// let x = join!(one(), two(), three()).await;
|
||||||
/// assert_eq!(x, (1, 2, 3));
|
/// assert_eq!(x, (1, 2, 3));
|
||||||
/// # };
|
/// # };
|
||||||
/// ```
|
/// ```
|
||||||
|
@ -71,6 +71,7 @@ pub macro join {
|
||||||
},
|
},
|
||||||
@rest: ()
|
@rest: ()
|
||||||
) => {{
|
) => {{
|
||||||
|
async move {
|
||||||
// The futures and whether they have completed
|
// The futures and whether they have completed
|
||||||
let mut state = ( $( UnsafeCell::new(($fut, false)), )* );
|
let mut state = ( $( UnsafeCell::new(($fut, false)), )* );
|
||||||
|
|
||||||
|
@ -127,5 +128,6 @@ pub macro join {
|
||||||
Poll::Pending
|
Poll::Pending
|
||||||
}
|
}
|
||||||
}).await
|
}).await
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,13 +32,13 @@ fn poll_n(val: usize, num: usize) -> PollN {
|
||||||
#[test]
|
#[test]
|
||||||
fn test_join() {
|
fn test_join() {
|
||||||
block_on(async move {
|
block_on(async move {
|
||||||
let x = join!(async { 0 });
|
let x = join!(async { 0 }).await;
|
||||||
assert_eq!(x, 0);
|
assert_eq!(x, 0);
|
||||||
|
|
||||||
let x = join!(async { 0 }, async { 1 });
|
let x = join!(async { 0 }, async { 1 }).await;
|
||||||
assert_eq!(x, (0, 1));
|
assert_eq!(x, (0, 1));
|
||||||
|
|
||||||
let x = join!(async { 0 }, async { 1 }, async { 2 });
|
let x = join!(async { 0 }, async { 1 }, async { 2 }).await;
|
||||||
assert_eq!(x, (0, 1, 2));
|
assert_eq!(x, (0, 1, 2));
|
||||||
|
|
||||||
let x = join!(
|
let x = join!(
|
||||||
|
@ -50,8 +50,17 @@ fn test_join() {
|
||||||
poll_n(5, 3),
|
poll_n(5, 3),
|
||||||
poll_n(6, 4),
|
poll_n(6, 4),
|
||||||
poll_n(7, 1)
|
poll_n(7, 1)
|
||||||
);
|
)
|
||||||
|
.await;
|
||||||
assert_eq!(x, (0, 1, 2, 3, 4, 5, 6, 7));
|
assert_eq!(x, (0, 1, 2, 3, 4, 5, 6, 7));
|
||||||
|
|
||||||
|
let y = String::new();
|
||||||
|
let x = join!(async {
|
||||||
|
println!("{}", &y);
|
||||||
|
1
|
||||||
|
})
|
||||||
|
.await;
|
||||||
|
assert_eq!(x, 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue