Skip to content

Commit

Permalink
Assure we wait for GUI thread to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 1, 2020
1 parent db6e067 commit 60eaea0
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/plumbing/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@ fn init_progress(
name: &str,
verbose: bool,
progress: bool,
) -> Option<progress::Either<progress::Log, prodash::tree::Item>> {
) -> (
Option<std::thread::JoinHandle<()>>,
Option<progress::Either<progress::Log, prodash::tree::Item>>,
) {
super::init_env_logger(verbose);
match (verbose, progress) {
(false, false) => None,
(true, false) => Some(progress::Either::Left(progress::Log::new(name))),
(false, false) => (None, None),
(true, false) => (None, Some(progress::Either::Left(progress::Log::new(name)))),
(true, true) | (false, true) => {
let progress = prodash::Tree::new();
let sub_progress = progress.add_child(name);
Expand All @@ -58,13 +61,17 @@ fn init_progress(
},
)
.expect("tui to come up without io error");
std::thread::spawn(move || smol::run(render_tui));
let handle = std::thread::spawn(move || smol::run(render_tui));

Some(progress::Either::Right(sub_progress))
(Some(handle), Some(progress::Either::Right(sub_progress)))
}
}
}

fn join<T>(handle: Option<std::thread::JoinHandle<T>>) -> Option<T> {
handle.and_then(|h| h.join().ok())
}

pub fn main() -> Result<()> {
use options::*;
let args = Args::from_args();
Expand All @@ -74,8 +81,10 @@ pub fn main() -> Result<()> {
verbose,
progress,
} => {
let progress = init_progress("verify-pack", verbose, progress);
core::verify_pack_or_pack_index(path, progress, stdout(), stderr())
let (handle, progress) = init_progress("verify-pack", verbose, progress);
let res = core::verify_pack_or_pack_index(path, progress, stdout(), stderr());
join(handle);
res
}
}?;
Ok(())
Expand Down

0 comments on commit 60eaea0

Please sign in to comment.