kevin.cianfarini
03/11/2019, 3:00 PMMarcelo Hernandez
03/11/2019, 4:48 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>)
if the blocking API call deals with IO.suspend fun getUser(userId: String) = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
dataStore.getUser(userId) // Blocking database query
}
kevin.cianfarini
03/12/2019, 12:09 AMMarcelo Hernandez
03/12/2019, 12:12 AMsuspendCoroutine
or suspendCancellableCoroutine
builders.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.coroutines/suspend-coroutine.html
https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/suspend-cancellable-coroutine.htmlwithContext
is what you'll have to wrap the blocking call with in order to run it within a suspend
function.kevin.cianfarini
03/12/2019, 12:18 AMsuspendCoroutine
is what I'm looking for :) thanksMarcelo Hernandez
03/12/2019, 12:19 AMsuspendCancellableCoroutine
.kevin.cianfarini
03/12/2019, 12:19 AMMarcelo Hernandez
03/12/2019, 12:20 AM