Skip to content

Commit 408ac23

Browse files
rami3ldjc
authored andcommitted
refactor(config): make update_all_channels() async
1 parent e97627e commit 408ac23

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ thiserror.workspace = true
8585
threadpool = "1"
8686
tokio-retry.workspace = true
8787
tokio.workspace = true
88+
tokio-stream.workspace = true
8889
toml = "0.8"
8990
tracing-opentelemetry = { workspace = true, optional = true }
9091
tracing-subscriber = { workspace = true, optional = true, features = ["env-filter"] }

src/cli/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ pub(crate) async fn update_all_channels(
290290
do_self_update: bool,
291291
force_update: bool,
292292
) -> Result<utils::ExitCode> {
293-
let toolchains = cfg.update_all_channels(force_update)?;
293+
let toolchains = cfg.update_all_channels(force_update).await?;
294294

295295
if toolchains.is_empty() {
296296
info!("no updatable toolchains installed");

src/config.rs

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::sync::Arc;
99
use anyhow::{anyhow, bail, Context, Result};
1010
use serde::Deserialize;
1111
use thiserror::Error as ThisError;
12+
use tokio_stream::StreamExt;
1213

1314
use crate::{
1415
cli::self_update::SelfUpdateMode,
@@ -894,7 +895,7 @@ impl Cfg {
894895
})
895896
}
896897

897-
pub(crate) fn update_all_channels(
898+
pub(crate) async fn update_all_channels(
898899
&self,
899900
force_update: bool,
900901
) -> Result<Vec<(ToolchainDesc, Result<UpdateStatus>)>> {
@@ -903,22 +904,17 @@ impl Cfg {
903904
let profile = self.get_profile()?;
904905

905906
// Update toolchains and collect the results
906-
let channels = channels.map(|(desc, mut distributable)| {
907-
let st = utils::run_future(distributable.update_extra(
908-
&[],
909-
&[],
910-
profile,
911-
force_update,
912-
false,
913-
));
914-
907+
let channels = tokio_stream::iter(channels).then(|(desc, mut distributable)| async move {
908+
let st = distributable
909+
.update_extra(&[], &[], profile, force_update, false)
910+
.await;
915911
if let Err(ref e) = st {
916912
(self.notify_handler)(Notification::NonFatalError(e));
917913
}
918914
(desc, st)
919915
});
920916

921-
Ok(channels.collect())
917+
Ok(channels.collect().await)
922918
}
923919

924920
#[cfg_attr(feature = "otel", tracing::instrument(skip_all))]

0 commit comments

Comments
 (0)