https://kotlinlang.org logo
#coroutines
Title
# coroutines
n

nicholasnet

02/12/2019, 9:20 PM
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

Dico

02/13/2019, 5:56 AM
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.
5 Views