I am just trying to learn Kotlin coroutine. This i...
# coroutines
n
I am just trying to learn Kotlin coroutine. This is what I have so far. I am trying to load several data using Kotlin to speed things up. However, I am not sure whether this is the right approach or not in terms of error handling. Does it leaks memory if any of the coroutine fails? Is there a better way to do this?
d
Your code is all running in a single thread.
You need to run your
async
coroutines on a different dispatcher
To achieve this, wrap all of the content in
runBlocking {}
using
withContext(Dispatchers.Default)
So
runBlocking { withContext(Dispatchers.Default) { old code } }
It will not leak any coroutines thanks to structured concurrency.