Add ActivityGuard::update() for in-place progress updates
Lets long-running operations update their status bar message without creating/dropping a new activity per iteration. Useful for loops like memory scoring where you want "scoring: 3/25 keyname" updating in place. Co-Authored-By: Proof of Concept <poc@bcachefs.org>
This commit is contained in:
parent
d2c0ef61a1
commit
121b46e1d2
1 changed files with 11 additions and 0 deletions
|
|
@ -42,6 +42,17 @@ pub struct ActivityGuard {
|
|||
id: u64,
|
||||
}
|
||||
|
||||
impl ActivityGuard {
|
||||
pub async fn update(&self, label: impl Into<String>) {
|
||||
let label = label.into();
|
||||
let mut st = self.agent.state.lock().await;
|
||||
if let Some(entry) = st.activities.iter_mut().find(|a| a.id == self.id) {
|
||||
entry.label = label;
|
||||
}
|
||||
st.changed.notify_one();
|
||||
}
|
||||
}
|
||||
|
||||
const ACTIVITY_LINGER: std::time::Duration = std::time::Duration::from_secs(5);
|
||||
|
||||
impl Drop for ActivityGuard {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue