@@ -921,7 +921,7 @@ where
921
921
///
922
922
/// Depending on the implementation of [`Persist::archive_persisted_channel`] the monitor
923
923
/// data could be moved to an archive location or removed entirely.
924
- pub fn archive_fully_resolved_channel_monitors ( & self ) {
924
+ pub async fn archive_fully_resolved_channel_monitors ( & self ) {
925
925
let mut have_monitors_to_prune = false ;
926
926
for monitor_holder in self . monitors . read ( ) . unwrap ( ) . values ( ) {
927
927
let logger = WithChannelMonitor :: from ( & self . logger , & monitor_holder. monitor , None ) ;
@@ -931,16 +931,20 @@ where
931
931
have_monitors_to_prune = true ;
932
932
}
933
933
if needs_persistence {
934
- self . persister . update_persisted_channel (
935
- monitor_holder. monitor . persistence_key ( ) ,
936
- None ,
937
- & monitor_holder. monitor ,
938
- ) ;
934
+ self . persister
935
+ . update_persisted_channel (
936
+ monitor_holder. monitor . persistence_key ( ) ,
937
+ None ,
938
+ & monitor_holder. monitor ,
939
+ )
940
+ . await ;
939
941
}
940
942
}
941
943
if have_monitors_to_prune {
942
944
let mut monitors = self . monitors . write ( ) . unwrap ( ) ;
943
- monitors. retain ( |channel_id, monitor_holder| {
945
+
946
+ let mut to_remove = Vec :: new ( ) ;
947
+ for ( channel_id, monitor_holder) in monitors. iter ( ) {
944
948
let logger = WithChannelMonitor :: from ( & self . logger , & monitor_holder. monitor , None ) ;
945
949
let ( is_fully_resolved, _) =
946
950
monitor_holder. monitor . check_and_update_full_resolution_status ( & logger) ;
@@ -951,12 +955,15 @@ where
951
955
channel_id
952
956
) ;
953
957
self . persister
954
- . archive_persisted_channel ( monitor_holder. monitor . persistence_key ( ) ) ;
955
- false
956
- } else {
957
- true
958
+ . archive_persisted_channel ( monitor_holder. monitor . persistence_key ( ) )
959
+ . await ;
960
+ to_remove. push ( channel_id. clone ( ) ) ;
958
961
}
959
- } ) ;
962
+ }
963
+
964
+ for channel_id in to_remove {
965
+ monitors. remove ( & channel_id) ;
966
+ }
960
967
}
961
968
}
962
969
0 commit comments