@@ -5,7 +5,7 @@ use std::{
55 Arc , LazyLock ,
66 atomic:: { AtomicU32 , Ordering :: Relaxed } ,
77 } ,
8- time:: { Duration , Instant } ,
8+ time:: { Duration , Instant , SystemTime , UNIX_EPOCH } ,
99} ;
1010
1111use futures:: future:: BoxFuture ;
@@ -89,7 +89,7 @@ pub struct ProgressPlugin {
8989 pub last_modules_count : Arc < Mutex < Option < u32 > > > ,
9090 pub last_active_module : Arc < Mutex < Option < ModuleIdentifier > > > ,
9191 pub last_state_info : Arc < Mutex < Vec < ProgressPluginStateInfo > > > ,
92- pub last_updated : Arc < Mutex < Option < Instant > > > ,
92+ pub last_updated : Arc < AtomicU32 > ,
9393}
9494
9595impl ProgressPlugin {
@@ -130,14 +130,14 @@ impl ProgressPlugin {
130130 }
131131
132132 async fn update_throttled ( & self ) -> Result < ( ) > {
133- let now = Instant :: now ( ) ;
134- let mut last_updated = self . last_updated . lock ( ) . await ;
135- let should_update = last_updated
136- . is_none_or ( |last| now . saturating_duration_since ( last ) > Duration :: from_millis ( 100 ) ) ;
133+ let current_time = SystemTime :: now ( )
134+ . duration_since ( UNIX_EPOCH )
135+ . expect ( "failed to get current time" )
136+ . as_millis ( ) as u32 ;
137137
138- if should_update {
138+ if current_time - self . last_updated . load ( Relaxed ) > 100 {
139139 self . update ( ) . await ?;
140- * last_updated = Some ( now ) ;
140+ self . last_updated . store ( current_time , Relaxed ) ;
141141 }
142142
143143 Ok ( ( ) )
0 commit comments