File tree 2 files changed +32
-2
lines changed
2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change
1
+ fn main ( ) {
2
+ futures:: executor:: block_on ( async {
3
+ async fn main ( ) -> Result < ( ) , std:: io:: Error > {
4
+ use async_macros:: try_select;
5
+ use futures:: future;
6
+ use std:: io:: { Error , ErrorKind } ;
7
+
8
+ let a = future:: pending :: < Result < u8 , Error > > ( ) ;
9
+ let b = future:: ready ( Err ( Error :: from ( ErrorKind :: Other ) ) ) ;
10
+ let c = future:: ready ( Ok ( 1u8 ) ) ;
11
+
12
+ assert_eq ! ( try_select!( a, b, c) . await ?, 1u8 ) ;
13
+ Ok ( ( ) )
14
+ }
15
+ main ( ) . await . unwrap ( ) ;
16
+ } ) ;
17
+ }
Original file line number Diff line number Diff line change 30
30
/// ```
31
31
#[ macro_export]
32
32
macro_rules! try_select {
33
- ( $( $fut: ident) ,* $( , ) ?) => { {
33
+ ( $( $fut: ident) ,+ $( , ) ?) => { {
34
34
async {
35
35
$(
36
36
// Move future into a local so that it is pinned in one place and
@@ -52,12 +52,25 @@ macro_rules! try_select {
52
52
let fut = unsafe { Pin :: new_unchecked( & mut $fut) } ;
53
53
let output = fut. take_output( ) . unwrap( ) ;
54
54
return Poll :: Ready ( output) ;
55
+ } else {
56
+ all_done = false ;
55
57
}
58
+ } else {
59
+ all_done = false ;
56
60
}
57
61
) *
58
62
59
63
if all_done {
60
- unimplemented!( ) ;
64
+ // We need to iterate over all items to not get an
65
+ // "unreachable code" warning.
66
+ let mut err = None ;
67
+ $(
68
+ if err. is_none( ) {
69
+ let fut = unsafe { Pin :: new_unchecked( & mut $fut) } ;
70
+ err = Some ( fut. take_output( ) . unwrap( ) ) ;
71
+ }
72
+ ) *
73
+ return Poll :: Ready ( err. unwrap( ) ) ;
61
74
} else {
62
75
Poll :: Pending
63
76
}
You can’t perform that action at this time.
0 commit comments