Hi, let's say I'd want to use `either { ... }` com...
# arrow
j
Hi, let's say I'd want to use
either { ... }
computation in a conventional (non-reactive, controller endpoints are not suspend!) Spring Boot RestController (for validation + effect-short-circuiting) ... what are my options: runBlocking, or some other recommended 'bridge to suspend-world' ? Obviously this concern could become obsolete if mainstream actually moves away from 'blocking Spring', but what recommendations (if any specific exist) are there until then ?
s
Hey @Jörg Winter, There is also
either.eager
which works with
@RestrictSuspension
and works for normal eager code. It also dissallows foreign
suspend
code so in contrast to
either
you cannot do the following.
Copy code
suspend fun mySuspend(): Unit = TODO()

suspend fun example1(): Either<String, Unit> = either {
  mySuspend() // Works fine
}

fun example2(): Either<String, Unit> =
  either.eager {
    mySuspend() // Won't compile
  }

fun normalFunction(): Unit = Unit

fun example3(): Either<String, Unit> =
  either.eager {
    normalFunction() // Works
  }
We had to make a distinction in name due to conflicting signatures otherwise 😞
The
eager
version is also available for
nullable
,
option
etc if you need it 🙂
j
Thank you, will try this 🙂
..and likewise for Validated and Either types I guess (not just Unit) With this there is no messing around with thread-pools in a non-reactive backend, nice
👍 3
And we can of course
import arrow.core.computations.either.eager as doEither
and it looks nice enough