Skip to content

Commit 0dd266a

Browse files
committed
fix
1 parent c3e3861 commit 0dd266a

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

crates/rspack_plugin_progress/src/lib.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

1111
use 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

9595
impl 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(())

examples/react/rspack.config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,6 @@ export default defineConfig({
5151
],
5252
},
5353
plugins: [
54-
new rspack.ProgressPlugin((percentage, message, info) => {
55-
console.info(
56-
percentage,
57-
message,
58-
info.builtModules,
59-
info.moduleIdentifier,
60-
);
61-
}),
6254
new rspack.HtmlRspackPlugin({
6355
template: './index.html',
6456
}),

0 commit comments

Comments
 (0)