Open alexandru opened 1 month ago
https://github.com/rssh/dotty-cps-async/issues/20
But not 100% sure. will try to reproduce.
Unless the finally
expression gets translated to a IO.guaranteed
by the CPS, I wouldn't expect it to run.
You say that IO interpreter skip IO.Cancelled unless inside guaranteed?
@rssh After IO.canceled
, the IO
interpreter will skip anything that's not in a special block e.g. guaranteed
, onCancel
, etc.
@rssh I opened an issue here as well, as I wanted to get your feedback, I apologize for the noise: https://github.com/rssh/cps-async-connect/issues/9
So this code:
try
println("Starting!")
IO.canceled.await
finally
println("Finalizing!")
Would need to be translated to the equivalent of this code:
IO {
println("Starting!")
}.flatMap { _ =>
IO.canceled
}.guarantee {
IO(println("Finalizing!"))
}
This is by design in Cats-Effect because interruption has its channel, separate from exceptions. This is because, in Java, it's pretty bad that people can catch and ignore InterruptedException
.
So, for example, it's fine if this code does not work with Cats-Effect:
try
IO.cancelled.await
catch
case e: Throwable =>
println("Caught interruption?")
But despite this, I still feel like the finally
should work because finally
is the most important part of a try
expression, being about resource safety. And in the context of a “direct style” syntax, finally
not working for interruption is bad, IMO. I'm not 100% sure, though, happy to be proven wrong.
What are your thoughts on this sample:
The finalizer doesn't get invoked, and unfortunately, I find the sample counter-intuitive.