zio-direct
zio-direct copied to clipboard
Surprising behavior when converting ZIO[_, _, Nothing]
I was converting some code:
val oldStyle =
for
_ <- printLine("Hi")
_ <- ZIO.fail("Error!")
yield ()
into
val directStyle =
defer {
printLine("Hi").run
ZIO.fail("Error!").run
}
and got this error message:
missing arguments for method apply in trait deferCall
defer {
Is there a fundamental reason why we cannot return ZIO
s with a Nothing
result inside defer
blocks?
If so, is there a way we could provide better error messages in this situation?
There are some great custom compilation error messages in this library, so I was surprised when I hit this one.
It took me a while to figure out what was actually causing the problem.
@deusaquilus This tripped me up again while working on a demonstration of how to react to a long running process.
object ReportLongRunning extends ZIOAppDefault:
val longRunning = defer {
ZIO.sleep(5.seconds).run
ZIO.debug("Finished long-running process").run
}
val reportLongRunning = defer {
ZIO.sleep(3.seconds).run
ZIO.debug("This is taking a while...").run
ZIO.never.run
}
def run =
longRunning.race(reportLongRunning)
Same error, so nothing really novel. It just made me realize that tricks around racing against aZIO.never
aren't possible currently.
I ran into this issue a couple of times too but I don't know what the problem is yet. I think it has to do with the overloaded variants of defer
.