以下の関数でエラー処理を実装しようとしています。私の問題は、Future [Either [Exception、MyValue]]のラップを解除し、MyValueをパラメーターとして使用するたびに「正しい」かどうかをテストする必要があることです。
戦略は、f1 から f4 のいずれかが失敗した場合、Future.flow を失敗させることです。
1 つの解決策は、Either[Exception,MyValue] を funcReturnFutureEitherX() のパラメーターとして funcReturnFutureEither3(f2()) のように渡すことですが、これはメイン プログラム MyFlowFunc() で処理する代わりに、エラー処理を下方に伝播するだけです。
以下の関数でエラー処理を実装し、ブロックなしで実行し続けるにはどうすればよいですか?
def MyFlowFunc():Future[(MyValue,MyValue,MyValue,MyValue)] =
val v = Future.flow {
// fail flow if below functions fails with a Either.Left()
val f1 = funcReturnFutureEither1()
val f2 = funcReturnFutureEither2(f1())
val f3 = funcReturnFutureEither3(f2())
val f4 = funcReturnFutureEither4(f1())
val res = (f1(),f2(),f3(),f4())
}
}
def funcReturnEitherX(val:MyValue):Future[Either[Exception,MyValue]]