@@ -7,7 +7,7 @@ use anyhow::{
7
7
Context ,
8
8
Result ,
9
9
} ;
10
- use futures:: future:: join_all ;
10
+ use futures:: future:: select_ok ;
11
11
use hyper_openssl:: client:: legacy:: HttpsConnector ;
12
12
use hyper_util:: client:: legacy:: connect:: HttpConnector ;
13
13
use hyper_util:: rt:: TokioExecutor ;
@@ -188,13 +188,15 @@ async fn create_client_with_config(config: &Config) -> Option<Client> {
188
188
config_with_invalid_certs_false,
189
189
) ;
190
190
191
- for ( description, strategy) in strategies {
192
- if let Some ( client) = try_create_client ( description, strategy) . await {
193
- return Some ( client) ;
194
- }
195
- }
191
+ let futures: Vec < _ > = strategies
192
+ . into_iter ( )
193
+ . map ( |( description, strategy) | Box :: pin ( try_create_client ( description, strategy) ) )
194
+ . collect ( ) ;
196
195
197
- None
196
+ match select_ok ( futures) . await {
197
+ Ok ( ( client, _) ) => Some ( client) ,
198
+ Err ( _) => None ,
199
+ }
198
200
}
199
201
200
202
fn create_strategies < ' a > (
@@ -260,21 +262,21 @@ fn create_strategies<'a>(
260
262
]
261
263
}
262
264
263
- async fn try_create_client ( description : & str , strategy : StrategyFuture < ' _ > ) -> Option < Client > {
265
+ async fn try_create_client ( description : & str , strategy : StrategyFuture < ' _ > ) -> Result < Client , ( ) > {
264
266
info ! ( "Attempting to create client with {}" , description) ;
265
267
match strategy. await {
266
268
Ok ( client) => {
267
269
if test_client ( & client) . await . is_ok ( ) {
268
270
info ! ( "Successfully created client with {}" , description) ;
269
- Some ( client)
271
+ Ok ( client)
270
272
} else {
271
273
warn ! ( "{} failed to connect." , description) ;
272
- None
274
+ Err ( ( ) )
273
275
}
274
276
}
275
277
Err ( e) => {
276
278
warn ! ( "Failed to create {}: {}" , description, e) ;
277
- None
279
+ Err ( ( ) )
278
280
}
279
281
}
280
282
}
0 commit comments