What is the advantage of using `either` over `eith...
# arrow
l
What is the advantage of using
either
over
either.eager
for suspending computations? If I use
either.eager
, will it simply block the current thread?
Copy code
suspend fun doSomethingLong(): Either<Error, Unit>

either.eager {
    doSomethingLong() // does it block the current thread?
}
s
Does that even compile?
l
Yes
Copy code
public final inline fun <E, A> eager(
    crossinline f: suspend EagerEffectScope<E>.() → A
): Either<E, A>
s
That should not compile
EagerEffectScope
is marked
@RestrictSuspension
l
It compiles at least inside of another
suspend
function, maybe that's the catch
s
Ah yes. It’s
inline
so it uses the
suspend
fro the outer scope.
l
Ah ok
Thanks!
That explains it.
s
Hmm.. It’s not compiling for me though 🤯
Where is your
suspend
call?
There is no
suspend
call inside
eager
in your screenshot
Only the call to
bind
but that should be coming from
eager
l
So the IDE shows
bind()
as the suspend function...
s
Yes, but that is coming from
EagerEffectScope
so it’s allowed
delay(100)
should not be allowed
l
Makes sense, I just misinterpreted the "suspend" marker in the gutter
Thanks for the explanation!
Ok, so in this case, is there a difference if I use
either
or
either.eager
? I suppose not. Or is there a reason why I should use
either
, e.g. because my outer function is suspending anyway?
s
In this case there is no difference at all. You’re free to use both.
755 Views