@@ -991,28 +991,32 @@ where
991
991
Some ( res) => res,
992
992
None => return Ok ( None ) ,
993
993
} ;
994
- let mut current_update_id = monitor. get_latest_update_id ( ) ;
994
+ let current_update_id = monitor. get_latest_update_id ( ) ;
995
995
let updates: Result < Vec < _ > , _ > =
996
996
list_res?. into_iter ( ) . map ( |name| UpdateName :: new ( name) ) . collect ( ) ;
997
997
let mut updates = updates?;
998
998
updates. sort_unstable ( ) ;
999
- // TODO: Parallelize this loop
1000
- for update_name in updates {
1001
- if update_name. 0 > current_update_id {
1002
- let update = self . read_monitor_update ( monitor_key, & update_name) . await ?;
1003
- monitor
1004
- . update_monitor ( & update, & self . broadcaster , & self . fee_estimator , & self . logger )
1005
- . map_err ( |e| {
1006
- log_error ! (
1007
- self . logger,
1008
- "Monitor update failed. monitor: {} update: {} reason: {:?}" ,
1009
- monitor_key,
1010
- update_name. as_str( ) ,
1011
- e
1012
- ) ;
1013
- io:: Error :: new ( io:: ErrorKind :: Other , "Monitor update failed" )
1014
- } ) ?;
1015
- }
999
+ let updates_to_load = updates. iter ( ) . filter ( |update| update. 0 > current_update_id) ;
1000
+ let mut update_futures = Vec :: with_capacity ( updates_to_load. clone ( ) . count ( ) ) ;
1001
+ for update_name in updates_to_load {
1002
+ update_futures. push ( ResultFuture :: Pending ( Box :: pin ( async move {
1003
+ ( update_name, self . read_monitor_update ( monitor_key, update_name) . await )
1004
+ } ) ) ) ;
1005
+ }
1006
+ for ( update_name, update_res) in MultiResultFuturePoller :: new ( update_futures) . await {
1007
+ let update = update_res?;
1008
+ monitor
1009
+ . update_monitor ( & update, & self . broadcaster , & self . fee_estimator , & self . logger )
1010
+ . map_err ( |e| {
1011
+ log_error ! (
1012
+ self . logger,
1013
+ "Monitor update failed. monitor: {} update: {} reason: {:?}" ,
1014
+ monitor_key,
1015
+ update_name. as_str( ) ,
1016
+ e
1017
+ ) ;
1018
+ io:: Error :: new ( io:: ErrorKind :: Other , "Monitor update failed" )
1019
+ } ) ?;
1016
1020
}
1017
1021
Ok ( Some ( ( block_hash, monitor) ) )
1018
1022
}
0 commit comments