Skip to main content

Module parallel

Module parallel 

Source
Expand description

Parallel step execution utilities.

Run independent workflow steps concurrently to reduce total wall-clock time. Two patterns are supported:

§Static parallelism (known number of steps)

Use tokio::try_join! when you know at compile time how many steps to run in parallel:

use ironflow_core::prelude::*;

let (files, status) = tokio::try_join!(
    Shell::new("ls -la"),
    Shell::new("git status"),
)?;

println!("files:\n{}", files.stdout());
println!("status:\n{}", status.stdout());

§Dynamic parallelism (runtime-determined number of steps)

Use try_join_all when the number of steps is determined at runtime:

use ironflow_core::prelude::*;

let commands = vec!["ls -la", "git status", "df -h"];
let results = try_join_all(
    commands.iter().map(|cmd| Shell::new(cmd).run())
).await?;

for (cmd, output) in commands.iter().zip(&results) {
    println!("{cmd}: {}", output.stdout());
}

§Concurrency-limited parallelism

Use try_join_all_limited to cap the number of steps running simultaneously (useful when launching many agent calls):

use ironflow_core::prelude::*;

let provider = ClaudeCodeProvider::new();
let prompts = vec!["Summarize file A", "Summarize file B", "Summarize file C"];

let results = try_join_all_limited(
    prompts.iter().map(|p| {
        Agent::new()
            .prompt(p)
            .model(Model::HAIKU)
            .max_budget_usd(0.10)
            .run(&provider)
    }),
    2, // at most 2 agent calls at a time
).await?;

Functions§

try_join_all
Run a collection of futures concurrently and collect their results.
try_join_all_limited
Run a collection of futures with a concurrency limit.