Macro core::future::join [−][src]
pub macro join($($fut : expr), + $(,) ?) {
...
}Expand description
同时轮询多个 futures,完成后,返回所有结果的元组。
虽然 join!(a, b) 与 (a.await, b.await) 相似,但 join! 同时轮询两个 futures,因此效率更高。
Examples
#![feature(future_join, future_poll_fn)]
use std::future::join;
async fn one() -> usize { 1 }
async fn two() -> usize { 2 }
let x = join!(one(), two()).await;
assert_eq!(x, (1, 2));Runjoin! 的参数是可变的,因此您可以传递任意数量的 futures:
#![feature(future_join, future_poll_fn)]
use std::future::join;
async fn one() -> usize { 1 }
async fn two() -> usize { 2 }
async fn three() -> usize { 3 }
let x = join!(one(), two(), three()).await;
assert_eq!(x, (1, 2, 3));Run