From 3120b5c6f258237e955d5b09080c098f7cbd54b9 Mon Sep 17 00:00:00 2001 From: Fabio Forni Date: Fri, 15 Sep 2023 08:30:20 +0200 Subject: [PATCH] trigger: Avoid an allocation in run_parallel() --- src/trigger.rs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/trigger.rs b/src/trigger.rs index c6c05e6..e138329 100644 --- a/src/trigger.rs +++ b/src/trigger.rs @@ -1,8 +1,10 @@ -use async_process::{Child, Command}; -use serde::Deserialize; use std::fmt::Display; use std::io; use std::process::ExitStatus; + +use async_process::{Child, Command}; +use futures::prelude::*; +use serde::Deserialize; use thiserror::Error; use crate::osenv::OsEnv; @@ -78,11 +80,11 @@ impl Trigger { } async fn run_parallel(&self) -> Result<(), Error> { - let mut wait_list = Vec::with_capacity(self.tasks.len()); - for t in &self.tasks { - wait_list.push(t.run()?.status()); - } - let results = futures::prelude::future::try_join_all(wait_list).await?; + let future_results = self + .tasks + .iter() + .map(|task| async move { task.run()?.status().await }); + let results = future::try_join_all(future_results).await?; for r in results { if !r.success() { return Err(Error::TaskFailed(r));