macro_rules! join { ($($tokens:tt)*) => { ... }; }
Expand description
Polls multiple futures simultaneously, returning a tuple of all results once complete.
While join!(a, b)
is similar to (a.await, b.await)
,
join!
polls both futures concurrently and therefore is more efficient.
This macro is only usable inside of async functions, closures, and blocks.
It is also gated behind the async-await
feature of this library, which is
activated by default.
§Examples
use futures::join;
let a = async { 1 };
let b = async { 2 };
assert_eq!(join!(a, b), (1, 2));
// `join!` is variadic, so you can pass any number of futures
let c = async { 3 };
let d = async { 4 };
let e = async { 5 };
assert_eq!(join!(c, d, e), (3, 4, 5));