feat: Await only the len of to_install

This commit is contained in:
Sergio Gasquez 2022-12-21 11:43:08 +00:00
parent c151489b14
commit cd2a326bf4

View File

@ -24,6 +24,7 @@ use espup::{
}; };
use log::{debug, info, warn}; use log::{debug, info, warn};
use miette::{IntoDiagnostic, Result}; use miette::{IntoDiagnostic, Result};
use std::time::Instant;
use std::{ use std::{
collections::HashSet, collections::HashSet,
fs::{remove_dir_all, remove_file, File}, fs::{remove_dir_all, remove_file, File},
@ -129,6 +130,8 @@ pub struct UninstallOpts {
/// Installs the Rust for ESP chips environment /// Installs the Rust for ESP chips environment
async fn install(args: InstallOpts) -> Result<()> { async fn install(args: InstallOpts) -> Result<()> {
let start = Instant::now();
initialize_logger(&args.log_level); initialize_logger(&args.log_level);
check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION")); check_for_update(env!("CARGO_PKG_NAME"), env!("CARGO_PKG_VERSION"));
info!("{} Installing esp-rs", emoji::DISC); info!("{} Installing esp-rs", emoji::DISC);
@ -221,7 +224,7 @@ async fn install(args: InstallOpts) -> Result<()> {
// With a list of applications to install, install them all in parallel. // With a list of applications to install, install them all in parallel.
let (tx, mut rx) = mpsc::channel::<Vec<String>>(32); let (tx, mut rx) = mpsc::channel::<Vec<String>>(32);
let installable_items = to_install.len();
for app in to_install { for app in to_install {
let tx = tx.clone(); let tx = tx.clone();
tokio::spawn(async move { tokio::spawn(async move {
@ -231,9 +234,10 @@ async fn install(args: InstallOpts) -> Result<()> {
}); });
} }
let mut exports = Vec::new(); // Read the results of the install tasks as they complete.
while let Some(name) = rx.recv().await { for _ in 0..installable_items {
exports.extend(name); let names = rx.recv().await.unwrap();
exports.extend(names);
} }
if args.profile_minimal { if args.profile_minimal {
@ -265,7 +269,8 @@ async fn install(args: InstallOpts) -> Result<()> {
"{} Please, source the export file, as state above, to properly setup the environment!", "{} Please, source the export file, as state above, to properly setup the environment!",
emoji::WARN emoji::WARN
); );
let duration = start.elapsed();
println!("Time elapsed in expensive_function() is: {:?}", duration);
Ok(()) Ok(())
} }