Skip to content

Commit

Permalink
trigger: Avoid an allocation in run_parallel()
Browse files Browse the repository at this point in the history
  • Loading branch information
livingsilver94 committed Sep 15, 2023
1 parent f5b6b4d commit 3120b5c
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/trigger.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 3120b5c

Please sign in to comment.