@@ -22,7 +22,7 @@ use crate::task::Poll;
22
22
/// async fn two() -> usize { 2 }
23
23
///
24
24
/// # let _ = async {
25
- /// let x = join!(one(), two());
25
+ /// let x = join!(one(), two()).await ;
26
26
/// assert_eq!(x, (1, 2));
27
27
/// # };
28
28
/// ```
@@ -39,7 +39,7 @@ use crate::task::Poll;
39
39
/// async fn three() -> usize { 3 }
40
40
///
41
41
/// # let _ = async {
42
- /// let x = join!(one(), two(), three());
42
+ /// let x = join!(one(), two(), three()).await ;
43
43
/// assert_eq!(x, (1, 2, 3));
44
44
/// # };
45
45
/// ```
@@ -71,61 +71,63 @@ pub macro join {
71
71
} ,
72
72
@rest : ( )
73
73
) => { {
74
- // The futures and whether they have completed
75
- let mut state = ( $( UnsafeCell :: new ( ( $fut, false ) ) , ) * ) ;
74
+ async move {
75
+ // The futures and whether they have completed
76
+ let mut state = ( $( UnsafeCell :: new ( ( $fut, false ) ) , ) * ) ;
76
77
77
- // Make sure the futures don't panic
78
- // if polled after completion, and
79
- // store their output separately
80
- let mut futures = ( $(
81
- ( {
82
- let ( $( $pos, ) * state, .. ) = & state;
78
+ // Make sure the futures don't panic
79
+ // if polled after completion, and
80
+ // store their output separately
81
+ let mut futures = ( $(
82
+ ( {
83
+ let ( $( $pos, ) * state, .. ) = & state;
83
84
84
- poll_fn ( move |cx| {
85
- // SAFETY: each future borrows a distinct element
86
- // of the tuple
87
- let ( fut, done) = unsafe { & mut * state. get ( ) } ;
85
+ poll_fn ( move |cx| {
86
+ // SAFETY: each future borrows a distinct element
87
+ // of the tuple
88
+ let ( fut, done) = unsafe { & mut * state. get ( ) } ;
88
89
89
- if * done {
90
- return Poll :: Ready ( None )
91
- }
90
+ if * done {
91
+ return Poll :: Ready ( None )
92
+ }
92
93
93
- // SAFETY: The futures are never moved
94
- match unsafe { Pin :: new_unchecked ( fut) . poll ( cx) } {
95
- Poll :: Ready ( val) => {
96
- * done = true ;
97
- Poll :: Ready ( Some ( val) )
94
+ // SAFETY: The futures are never moved
95
+ match unsafe { Pin :: new_unchecked ( fut) . poll ( cx) } {
96
+ Poll :: Ready ( val) => {
97
+ * done = true ;
98
+ Poll :: Ready ( Some ( val) )
99
+ }
100
+ Poll :: Pending => Poll :: Pending
98
101
}
99
- Poll :: Pending => Poll :: Pending
100
- }
101
- } )
102
- } , None ) ,
103
- ) * ) ;
102
+ } )
103
+ } , None ) ,
104
+ ) * ) ;
104
105
105
- poll_fn ( move |cx| {
106
- let mut done = true ;
106
+ poll_fn ( move |cx| {
107
+ let mut done = true ;
107
108
108
- $(
109
- let ( $( $pos, ) * ( fut, out) , .. ) = & mut futures;
109
+ $(
110
+ let ( $( $pos, ) * ( fut, out) , .. ) = & mut futures;
110
111
111
- // SAFETY: The futures are never moved
112
- match unsafe { Pin :: new_unchecked ( fut) . poll ( cx) } {
113
- Poll :: Ready ( Some ( val) ) => * out = Some ( val) ,
114
- // the future was already done
115
- Poll :: Ready ( None ) => { } ,
116
- Poll :: Pending => done = false ,
117
- }
118
- ) *
112
+ // SAFETY: The futures are never moved
113
+ match unsafe { Pin :: new_unchecked ( fut) . poll ( cx) } {
114
+ Poll :: Ready ( Some ( val) ) => * out = Some ( val) ,
115
+ // the future was already done
116
+ Poll :: Ready ( None ) => { } ,
117
+ Poll :: Pending => done = false ,
118
+ }
119
+ ) *
119
120
120
- if done {
121
- // Extract all the outputs
122
- Poll :: Ready ( ( $( {
123
- let ( $( $pos, ) * ( _, val) , .. ) = & mut futures;
124
- val. unwrap ( )
125
- } ) , * ) )
126
- } else {
127
- Poll :: Pending
128
- }
129
- } ) . await
121
+ if done {
122
+ // Extract all the outputs
123
+ Poll :: Ready ( ( $( {
124
+ let ( $( $pos, ) * ( _, val) , .. ) = & mut futures;
125
+ val. unwrap ( )
126
+ } ) , * ) )
127
+ } else {
128
+ Poll :: Pending
129
+ }
130
+ } ) . await
131
+ }
130
132
} }
131
133
}
0 commit comments