|
1 |
| -/// Waits on multiple concurrent branches, returning when **all** branches |
2 |
| -/// complete. |
3 |
| -/// |
4 |
| -/// The `join!` macro must be used inside of async functions, closures, and |
5 |
| -/// blocks. |
6 |
| -/// |
7 |
| -/// The `join!` macro takes a list of async expressions and evaluates them |
8 |
| -/// concurrently on the same task. Each async expression evaluates to a future |
9 |
| -/// and the futures from each expression are multiplexed on the current task. |
10 |
| -/// |
11 |
| -/// When working with async expressions returning `Result`, `join!` will wait |
12 |
| -/// for **all** branches complete regardless if any complete with `Err`. Use |
13 |
| -/// [`try_join!`] to return early when `Err` is encountered. |
14 |
| -/// |
15 |
| -/// [`try_join!`]: crate::try_join |
16 |
| -/// |
17 |
| -/// # Notes |
18 |
| -/// |
19 |
| -/// The supplied futures are stored inline and do not require allocating a |
20 |
| -/// `Vec`. |
21 |
| -/// |
22 |
| -/// ### Runtime characteristics |
23 |
| -/// |
24 |
| -/// By running all async expressions on the current task, the expressions are |
25 |
| -/// able to run **concurrently** but not in **parallel**. This means all |
26 |
| -/// expressions are run on the same thread and if one branch blocks the thread, |
27 |
| -/// all other expressions will be unable to continue. If parallelism is |
28 |
| -/// required, spawn each async expression using [`tokio::spawn`] and pass the |
29 |
| -/// join handle to `join!`. |
30 |
| -/// |
31 |
| -/// [`tokio::spawn`]: crate::spawn |
32 |
| -/// |
33 |
| -/// # Examples |
34 |
| -/// |
35 |
| -/// Basic join with two branches |
36 |
| -/// |
37 |
| -/// ``` |
38 |
| -/// async fn do_stuff_async() { |
39 |
| -/// // async work |
40 |
| -/// } |
41 |
| -/// |
42 |
| -/// async fn more_async_work() { |
43 |
| -/// // more here |
44 |
| -/// } |
45 |
| -/// |
46 |
| -/// #[tokio::main] |
47 |
| -/// async fn main() { |
48 |
| -/// let (first, second) = tokio::join!( |
49 |
| -/// do_stuff_async(), |
50 |
| -/// more_async_work()); |
51 |
| -/// |
52 |
| -/// // do something with the values |
53 |
| -/// } |
54 |
| -/// ``` |
55 |
| -#[macro_export] |
56 |
| -#[cfg_attr(docsrs, doc(cfg(feature = "macros")))] |
57 |
| -macro_rules! join { |
| 1 | +macro_rules! doc { |
| 2 | + ($join:item) => { |
| 3 | + /// Waits on multiple concurrent branches, returning when **all** branches |
| 4 | + /// complete. |
| 5 | + /// |
| 6 | + /// The `join!` macro must be used inside of async functions, closures, and |
| 7 | + /// blocks. |
| 8 | + /// |
| 9 | + /// The `join!` macro takes a list of async expressions and evaluates them |
| 10 | + /// concurrently on the same task. Each async expression evaluates to a future |
| 11 | + /// and the futures from each expression are multiplexed on the current task. |
| 12 | + /// |
| 13 | + /// When working with async expressions returning `Result`, `join!` will wait |
| 14 | + /// for **all** branches complete regardless if any complete with `Err`. Use |
| 15 | + /// [`try_join!`] to return early when `Err` is encountered. |
| 16 | + /// |
| 17 | + /// [`try_join!`]: crate::try_join |
| 18 | + /// |
| 19 | + /// # Notes |
| 20 | + /// |
| 21 | + /// The supplied futures are stored inline and do not require allocating a |
| 22 | + /// `Vec`. |
| 23 | + /// |
| 24 | + /// ### Runtime characteristics |
| 25 | + /// |
| 26 | + /// By running all async expressions on the current task, the expressions are |
| 27 | + /// able to run **concurrently** but not in **parallel**. This means all |
| 28 | + /// expressions are run on the same thread and if one branch blocks the thread, |
| 29 | + /// all other expressions will be unable to continue. If parallelism is |
| 30 | + /// required, spawn each async expression using [`tokio::spawn`] and pass the |
| 31 | + /// join handle to `join!`. |
| 32 | + /// |
| 33 | + /// [`tokio::spawn`]: crate::spawn |
| 34 | + /// |
| 35 | + /// # Examples |
| 36 | + /// |
| 37 | + /// Basic join with two branches |
| 38 | + /// |
| 39 | + /// ``` |
| 40 | + /// async fn do_stuff_async() { |
| 41 | + /// // async work |
| 42 | + /// } |
| 43 | + /// |
| 44 | + /// async fn more_async_work() { |
| 45 | + /// // more here |
| 46 | + /// } |
| 47 | + /// |
| 48 | + /// #[tokio::main] |
| 49 | + /// async fn main() { |
| 50 | + /// let (first, second) = tokio::join!( |
| 51 | + /// do_stuff_async(), |
| 52 | + /// more_async_work()); |
| 53 | + /// |
| 54 | + /// // do something with the values |
| 55 | + /// } |
| 56 | + /// ``` |
| 57 | + #[macro_export] |
| 58 | + #[cfg_attr(docsrs, doc(cfg(feature = "macros")))] |
| 59 | + $join |
| 60 | + }; |
| 61 | +} |
| 62 | + |
| 63 | +#[cfg(doc)] |
| 64 | +doc! {macro_rules! join { |
| 65 | + (@ { |
| 66 | + ( $($count:tt)* ) |
| 67 | + ( $($total:tt)* ) |
| 68 | + $( ( $($skip:tt)* ) $e:expr, )* |
| 69 | + }) => { |
| 70 | + unimplemented!() |
| 71 | + }; |
| 72 | + |
| 73 | + (@ { ( $($s:tt)* ) ( $($n:tt)* ) $($t:tt)* } $e:expr, $($r:tt)* ) => { |
| 74 | + unimplemented!() |
| 75 | + }; |
| 76 | + |
| 77 | + ( $($e:expr),+ $(,)?) => { |
| 78 | + unimplemented!() |
| 79 | + }; |
| 80 | + |
| 81 | + () => { async {}.await } |
| 82 | +}} |
| 83 | + |
| 84 | +#[cfg(not(doc))] |
| 85 | +doc! {macro_rules! join { |
58 | 86 | (@ {
|
59 | 87 | // One `_` for each branch in the `join!` macro. This is not used once
|
60 | 88 | // normalization is complete.
|
@@ -163,4 +191,4 @@ macro_rules! join {
|
163 | 191 | };
|
164 | 192 |
|
165 | 193 | () => { async {}.await }
|
166 |
| -} |
| 194 | +}} |
0 commit comments