Jörg Winter
04/14/2021, 2:12 PMeither { ... }
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 ?simon.vergauwen
04/14/2021, 2:16 PMeither.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.
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
}
simon.vergauwen
04/14/2021, 2:18 PMsimon.vergauwen
04/14/2021, 2:18 PMeager
version is also available for nullable
, option
etc if you need it 🙂Jörg Winter
04/14/2021, 2:19 PMJörg Winter
04/14/2021, 2:21 PMJörg Winter
04/14/2021, 7:02 PMimport arrow.core.computations.either.eager as doEither
and it looks nice enough