Update try_op.rs

This commit is contained in:
crStiv 2025-02-11 02:39:57 +01:00 committed by GitHub
parent af884299aa
commit 59540fbb90
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 24 deletions

View File

@ -345,33 +345,35 @@ where
}
}
// TODO: Implement TryParallel
// pub struct TryParallel<Op1, Op2> {
// op1: Op1,
// op2: Op2,
// }
// Implement TryParallel
pub struct TryParallel<Op1, Op2> {
op1: Op1,
op2: Op2,
}
// impl<Op1, Op2> TryParallel<Op1, Op2> {
// pub fn new(op1: Op1, op2: Op2) -> Self {
// Self { op1, op2 }
// }
// }
impl<Op1, Op2> TryParallel<Op1, Op2> {
pub fn new(op1: Op1, op2: Op2) -> Self {
Self { op1, op2 }
}
}
// impl<Op1, Op2> TryOp for TryParallel<Op1, Op2>
// where
// Op1: TryOp,
// Op2: TryOp<Input = Op1::Input, Output = Op1::Output, Error = Op1::Error>,
// {
// type Input = Op1::Input;
// type Output = (Op1::Output, Op2::Output);
// type Error = Op1::Error;
impl<Op1, Op2> op::Op for TryParallel<Op1, Op2>
where
Op1: TryOp,
Op2: TryOp<Input = Op1::Input, Error = Op1::Error>,
{
type Input = Op1::Input;
type Output = Result<(Op1::Output, Op2::Output), Op1::Error>;
// #[inline]
// async fn try_call(&self, input: Self::Input) -> Result<Self::Output, Self::Error> {
// let (output1, output2) = tokio::join!(self.op1.try_call(input.clone()), self.op2.try_call(input));
// Ok((output1?, output2?))
// }
// }
#[inline]
async fn try_call(&self, input: Self::Input) -> Result<(Op1::Output, Op2::Output), Op1::Error> {
use futures::try_join;
try_join!(
self.op1.try_call(input.clone()),
self.op2.try_call(input)
)
}
}
#[cfg(test)]
mod tests {