mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-04-21 13:08:42 +00:00
Merge pull request #164 from NobodyXu/optimize-tokio-usage
This commit is contained in:
commit
764a960c90
1 changed files with 12 additions and 5 deletions
17
src/main.rs
17
src/main.rs
|
@ -11,7 +11,7 @@ use miette::{miette, IntoDiagnostic, Result, WrapErr};
|
||||||
use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode};
|
use simplelog::{ColorChoice, ConfigBuilder, TermLogger, TerminalMode};
|
||||||
use structopt::StructOpt;
|
use structopt::StructOpt;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
use tokio::{process::Command, runtime::Runtime};
|
use tokio::{process::Command, runtime::Runtime, task::JoinError};
|
||||||
|
|
||||||
use cargo_binstall::{
|
use cargo_binstall::{
|
||||||
bins,
|
bins,
|
||||||
|
@ -84,6 +84,7 @@ enum MainExit {
|
||||||
Success(Duration),
|
Success(Duration),
|
||||||
Error(BinstallError),
|
Error(BinstallError),
|
||||||
Report(miette::Report),
|
Report(miette::Report),
|
||||||
|
JoinErr(JoinError),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Termination for MainExit {
|
impl Termination for MainExit {
|
||||||
|
@ -99,6 +100,11 @@ impl Termination for MainExit {
|
||||||
eprintln!("{err:?}");
|
eprintln!("{err:?}");
|
||||||
ExitCode::from(16)
|
ExitCode::from(16)
|
||||||
}
|
}
|
||||||
|
Self::JoinErr(err) => {
|
||||||
|
error!("Fatal error:");
|
||||||
|
eprintln!("{err:?}");
|
||||||
|
ExitCode::from(17)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,19 +113,20 @@ fn main() -> MainExit {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
|
|
||||||
let rt = Runtime::new().unwrap();
|
let rt = Runtime::new().unwrap();
|
||||||
let result = rt.block_on(entry());
|
let handle = rt.spawn(entry());
|
||||||
|
let result = rt.block_on(handle);
|
||||||
drop(rt);
|
drop(rt);
|
||||||
|
|
||||||
let done = start.elapsed();
|
let done = start.elapsed();
|
||||||
debug!("run time: {done:?}");
|
debug!("run time: {done:?}");
|
||||||
|
|
||||||
result
|
result.map_or_else(MainExit::JoinErr, |res| {
|
||||||
.map(|_| MainExit::Success(done))
|
res.map(|_| MainExit::Success(done)).unwrap_or_else(|err| {
|
||||||
.unwrap_or_else(|err| {
|
|
||||||
err.downcast::<BinstallError>()
|
err.downcast::<BinstallError>()
|
||||||
.map(MainExit::Error)
|
.map(MainExit::Error)
|
||||||
.unwrap_or_else(MainExit::Report)
|
.unwrap_or_else(MainExit::Report)
|
||||||
})
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn entry() -> Result<()> {
|
async fn entry() -> Result<()> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue