【发布时间】:2022-01-06 21:46:42
【问题描述】:
我正在尝试更改 ZIO 的 example code 以适应我想要的,但遇到了问题。我想在不同的 rpc 调用之间实现功能,但我似乎无法让它工作,因为在下面的示例中,只有 while 循环 rcpMethod3() 和 rcpMethod4() 被执行,而 rcpMethod1() 和 rcpMethod2()没有。
我想执行所有的rcpMethods 和 while 循环。
object Client extends App {
val clientLayer: Layer[Throwable, ClientZLayer] =
ClientZLayer.live(
ZManagedChannel(
ManagedChannelBuilder.forAddress("localhost", 8980).usePlaintext()
)
)
// rcp methods
def rcpMethod1(): ZIO[ClientZLayer with Console, Status, Unit] = {
for {
response <- ClientZLayer.rcpMethod1(Greeting("Hi"))
_ <- putStrLn(s"""Greeted: "${response.name}".""")
} yield ()
}
// Run the code
final def run(args: List[String]) = {
(for {
_ <- rcpMethod1()
_ <- rcpMethod2()
} yield ()).provideCustomLayer(clientLayer).exitCode
while(condition) {
// bla bla
}
(for {
_ <- rcpMethod3()
_ <- rcpMethod4()
} yield ()).provideCustomLayer(clientLayer).exitCode
}
}
【问题讨论】: