Skip to content

Commit

Permalink
use drop to ensure progress cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
evmar committed Jun 29, 2023
1 parent 6d81788 commit ca14283
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ pub trait Progress {

/// Log some (debug) information, without corrupting the progress display.
fn log(&mut self, msg: &str);

/// Called when the overall build has completed (success or failure), to allow
/// cleaning up the display.
fn finish(&mut self);
}

/// Currently running build task, as tracked for progress updates.
Expand Down Expand Up @@ -109,8 +105,6 @@ impl Progress for DumbConsoleProgress {
fn log(&mut self, msg: &str) {
println!("{}", msg);
}

fn finish(&mut self) {}
}

/// Progress implementation for "fancy" console, with progress bar etc.
Expand Down Expand Up @@ -184,9 +178,11 @@ impl Progress for FancyConsoleProgress {
fn log(&mut self, msg: &str) {
self.state.lock().unwrap().log(msg);
}
}

fn finish(&mut self) {
self.state.lock().unwrap().finish();
impl Drop for FancyConsoleProgress {
fn drop(&mut self) {
self.state.lock().unwrap().cleanup();
}
}

Expand Down Expand Up @@ -260,7 +256,7 @@ impl FancyState {
self.dirty();
}

fn finish(&mut self) {
fn cleanup(&mut self) {
self.clear_progress();
self.done = true;
self.dirty(); // let thread quit
Expand Down
1 change: 0 additions & 1 deletion src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ fn build(
}

let ret = trace::scope("work.run", || work.run());
progress.finish();
ret
}

Expand Down

0 comments on commit ca14283

Please sign in to comment.