mirror of
https://github.com/cargo-bins/cargo-binstall.git
synced 2025-05-07 12:40:04 +00:00
Optimize: Avoid double spawn
if no_confirm
Signed-off-by: Jiahao XU <Jiahao_XU@outlook.com>
This commit is contained in:
parent
de7ecad32c
commit
2bf7640729
1 changed files with 34 additions and 20 deletions
54
src/main.rs
54
src/main.rs
|
@ -251,23 +251,23 @@ async fn entry() -> Result<()> {
|
|||
|
||||
let temp_dir_path: Arc<Path> = Arc::from(temp_dir.path());
|
||||
|
||||
// Resolve crates
|
||||
let tasks: Vec<_> = crate_names
|
||||
.into_iter()
|
||||
.map(|crate_name| {
|
||||
tokio::spawn(resolve(
|
||||
opts.clone(),
|
||||
crate_name,
|
||||
desired_targets.clone(),
|
||||
cli_overrides.clone(),
|
||||
temp_dir_path.clone(),
|
||||
install_path.clone(),
|
||||
client.clone(),
|
||||
))
|
||||
})
|
||||
.collect();
|
||||
|
||||
let tasks: Vec<_> = if !opts.dry_run && !opts.no_confirm {
|
||||
// Resolve crates
|
||||
let tasks: Vec<_> = crate_names
|
||||
.into_iter()
|
||||
.map(|crate_name| {
|
||||
tokio::spawn(resolve(
|
||||
opts.clone(),
|
||||
crate_name,
|
||||
desired_targets.clone(),
|
||||
cli_overrides.clone(),
|
||||
temp_dir_path.clone(),
|
||||
install_path.clone(),
|
||||
client.clone(),
|
||||
))
|
||||
})
|
||||
.collect();
|
||||
|
||||
// Confirm
|
||||
let mut resolutions = Vec::with_capacity(tasks.len());
|
||||
for task in tasks {
|
||||
|
@ -290,17 +290,31 @@ async fn entry() -> Result<()> {
|
|||
})
|
||||
.collect()
|
||||
} else {
|
||||
// Install without confirm
|
||||
tasks
|
||||
// Resolve crates and install without confirmation
|
||||
crate_names
|
||||
.into_iter()
|
||||
.map(|task| {
|
||||
.map(|crate_name| {
|
||||
let opts = opts.clone();
|
||||
let temp_dir_path = temp_dir_path.clone();
|
||||
let desired_target = desired_targets.clone();
|
||||
let jobserver_client = jobserver_client.clone();
|
||||
let desired_targets = desired_targets.clone();
|
||||
let client = client.clone();
|
||||
let cli_overrides = cli_overrides.clone();
|
||||
let install_path = install_path.clone();
|
||||
|
||||
tokio::spawn(async move {
|
||||
let resolution = await_task(task).await?;
|
||||
let resolution = resolve(
|
||||
opts.clone(),
|
||||
crate_name,
|
||||
desired_targets.clone(),
|
||||
cli_overrides,
|
||||
temp_dir_path.clone(),
|
||||
install_path,
|
||||
client,
|
||||
)
|
||||
.await?;
|
||||
|
||||
install(
|
||||
resolution,
|
||||
opts,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue