@@ -22,6 +22,10 @@ fn main() {
22
22
}
23
23
24
24
async fn common_code ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
25
+ // Allows for one iteration where we see no progress but next loop should go
26
+ // into first branch
27
+ let mut seen_no_progress = false ;
28
+
25
29
let client = reqwest:: Client :: new ( ) ;
26
30
let mut state = DataState :: None ;
27
31
@@ -35,22 +39,22 @@ async fn common_code() -> Result<(), Box<dyn std::error::Error>> {
35
39
assert_eq ! ( status_code, & 200 ) ;
36
40
break ;
37
41
} else {
38
- let is_able_to_make_progress = state
39
- . get ( || {
40
- let req = client . get ( "http://httpbin.org/get" ) ;
41
- let response_handler = |resp : reqwest :: Result < reqwest :: Response > | async {
42
- resp . map ( |resp| resp . status ( ) )
43
- . context ( "Request failed, got an error back" )
44
- } ;
45
- let ui_notify = || {
46
- println ! (
47
- "Request Completed, this is where you would wake up your UI thread"
48
- ) ;
49
- } ;
50
- Awaiting ( fetch_plus ( req , response_handler , ui_notify ) )
51
- } )
52
- . is_able_to_make_progress ( ) ;
53
- assert ! ( is_able_to_make_progress ) ;
42
+ let outcome = state. get ( || {
43
+ let req = client . get ( "http://httpbin.org/get" ) ;
44
+ let response_handler = | resp : reqwest :: Result < reqwest :: Response > | async {
45
+ resp . map ( |resp| resp . status ( ) )
46
+ . context ( "Request failed, got an error back" )
47
+ } ;
48
+ let ui_notify = || {
49
+ println ! ( "Request Completed, this is where you would wake up your UI thread" ) ;
50
+ } ;
51
+ Awaiting ( fetch_plus ( req , response_handler , ui_notify ) )
52
+ } ) ;
53
+ assert ! ( !seen_no_progress ) ;
54
+ if outcome . is_unable_to_make_progress ( ) {
55
+ // We should never get into this branch again
56
+ seen_no_progress = true ;
57
+ }
54
58
reqwest_cross:: yield_now ( ) . await ;
55
59
}
56
60
}
0 commit comments