Ensure destructors are ran before std::process::exit (#134)

See comments in code for more details.
This commit is contained in:
Paweł Romanowski 2021-02-08 11:04:01 +01:00 committed by GitHub
parent a5db490066
commit 836f557829
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -30,6 +30,15 @@ enum ExitCode {
}
fn main() -> Result<()> {
// std::process::exit doesn't guarantee that all destructors will be ran,
// therefore we wrap "main" code in another function to guarantee that.
// See: https://doc.rust-lang.org/stable/std/process/fn.exit.html
// Also see: https://www.youtube.com/watch?v=zQC8T71Y8e4
let exit_code = run_main()?;
std::process::exit(exit_code);
}
fn run_main() -> Result<i32> {
let mut opts = LycheeOptions::from_args();
// Load a potentially existing config file and merge it into the config from the CLI
@ -48,8 +57,8 @@ fn main() -> Result<()> {
}
None => tokio::runtime::Runtime::new()?,
};
let errorcode = runtime.block_on(run(cfg, opts.inputs()))?;
std::process::exit(errorcode);
runtime.block_on(run(cfg, opts.inputs()))
}
fn show_progress(progress_bar: &Option<ProgressBar>, response: &Response, verbose: bool) {