Skip to main content

zeph_core/pipeline/
parallel.rs

1// SPDX-FileCopyrightText: 2026 Andrei G <bug-ops>
2// SPDX-License-Identifier: MIT OR Apache-2.0
3
4use super::PipelineError;
5use super::step::Step;
6
7pub struct ParallelStep<A, B> {
8    a: A,
9    b: B,
10}
11
12#[must_use]
13pub fn parallel<A, B>(a: A, b: B) -> ParallelStep<A, B> {
14    ParallelStep { a, b }
15}
16
17impl<A, B> Step for ParallelStep<A, B>
18where
19    A: Step,
20    B: Step<Input = A::Input>,
21    A::Input: Clone,
22{
23    type Input = A::Input;
24    type Output = (A::Output, B::Output);
25
26    async fn run(&self, input: Self::Input) -> Result<Self::Output, PipelineError> {
27        let input_b = input.clone();
28        let (ra, rb) = tokio::join!(self.a.run(input), self.b.run(input_b));
29        Ok((ra?, rb?))
30    }
31}