kyleg
02/12/2020, 4:45 PMIO.parMapN
such that I jump back into a differnet coroutinecontext after the parallel operations have completed?
IO.parMapN(IOThread, someIO, anotherIO) { a, b ->
continueOn(MainThread)
// do stuff
}
Does not appear I can call continueOn
inside parMapN
. I tried IO.parMapN(…).continueOn(MainThread)
but that doesn’t seem to actually switch me correctly. I actually have
ReaderT {
... IO.parMapN(IOThread, ...).continueOn(MainThread)
}.run(context).fix().unsafeRunAsync {
it.fold({}, { myLiveData.value = it })
}
and Android throws, telling me I can’t call setValue
from a background thread.
So the continueOn
doesn’t seem to change the coroutine context back to the main thread that way.kyleg
02/12/2020, 4:47 PMIO.parMapN(MainThread, FormerlyIOWrappedSuspend, ...) { ... }
fun FormerlyIOWrappedSuspend() = IO.fx {
continueOn(IOThread)
val rv = effect { suspendFn() }.bind()
continueOn(MainThread)
rv
}