Is there something similar to `IO.handleError { }`...
# arrow
r
Is there something similar to
IO.handleError { }
that doesn't require I provide an
IO<A>
(perhaps one which requires an
IO<Unit>
)? I have a method which returns an
IO<A>
, but I need to guarantee certain additional IO operations happen if the former IO fails (and in this case, I can't return an
IO<A>
because that part failed).
r
if this is related to ensuring resource safety and properly closing things you can use bracketCase
bracketing guarantees finalisers are invoked no matter what even in the presence of external cancelation
s
If you provide a snippet I'd happily help you write it with bracketCase or similar operators to satisfy your use case :)
r
Hopefully this makes sense.
inputFile
doesn't get deleted if the command fails (because it fails with an exception).
s
It first creates the file, and when the command in
use
fails it is guaranteed to go through
release
. It’s similar to
try-with-resources
except that it works within
IO
so it supports concurrency, parallelism, cancellation etc while guaranteeing resource safety 🙂
r
Maybe I am missing a dependency, but
bracketCase
is showing as an unresolved reference
s
If you have
IO
on the classpath than you should also have
bracketCase
IIRC.
r
IO
has
bracketCase
, yes, but
IOEffect
does not
s
Why are you using
IOEffect
? And
IOEffect
should extend from
Async
and thus also
Bracket
.
r
You are using
IOEffect
. Your code uses
IO.effect
which resolves as
fun Companion.effect(): IOEffect = object : arrow.effects.extensions.IOEffect {  }
Oh, the problem is there is a compiler error earlier on
effect
is a zero argument method, but you pass it a lambda
s
What version on Arrow are you on? I have master in my head 😅
r
0.9.0
s
I'm on my phone. Oh yeah I'm talking about snapshot
I can help rewrite to 0.9 when I'm home
r
If I just omit
effect
and make a normal
IO
then it works
s
That works fine 2