simon.vergauwen
05/01/2020, 9:33 AMsuspend in any IO program, and forget almost all operators up to the aync/concurrent once such as parTraverse, continueOn, bracket, parMapN, etc.
suspend fun concurrentProgramA(): A = IO { .... }.suspended()
suspend fun concurrentProgramB(): B = IO { ... }.suspended()
fun normalValue(): C = ...
suspend fun otherProgram(): : D {
val x = otherSuspendingFunctions()
otherIO(x).suspended()
}
suspend fun parallel(): Tuple<A, B, C, D> =
IO.parTupledN(IO { concurrentProgramA() }, IO { concurrentProgramB() }, IO { normalValue() }, IO { otherProgram() })
.suspended()
In other words there is only the need to use IO when you need an concurrent or async operator, and expose it as suspend.
As long as you recapture in IO then cancellation will be wired automatically, if you want to wire cancellation to KotlinX then you need to use suspendCancellable() from the KotlinX integration.