genovich
08/18/2020, 3:13 PMeffect() inside ConcurrentSyntax?kioba
08/18/2020, 3:20 PMeffect removes the eager execution and will be triggered only at the end rendering the suspend function invocation lazy.
I believe that is the reason why Arrow-fx is created to allow lazy Coroutines evaluations compared to KotlinX-Coroutines librarysimon.vergauwen
08/18/2020, 3:24 PMeffect is a @RestrictSuspension DSL, which means that all foreign effects beside F need to explicitly wrapped in effect.
If we wouldn't do it, then we cannot guarantee that suspend functions are safely interleaved into `F`'s execution like @kioba mentioned 🙂simon.vergauwen
08/18/2020, 3:26 PMsuspend effects.
val x: IO<Unit> = io.flatMap {
foreignSuspendFunction()
IO { otherSupendFunction() }
}
In the above pseudo code (which could be the result without @RestrictSuspension or effect), you'd see that foreignSuspendFunction() gets executed whilst building the IO value instead of when running the IO value.simon.vergauwen
08/18/2020, 3:27 PMIO as a suspend library, which took quite a while to crack the correct encoding which offer the same guarantees as IO.