Andy Gibel
12/16/2019, 4:59 PMbezrukov
12/16/2019, 5:16 PMThis function should not be used from a coroutine. It is designed to bridge regular blocking code to libraries that are written in suspending style, to be used in main functions and in tests.
Andy Gibel
12/16/2019, 5:18 PMjw
12/16/2019, 5:19 PMAndy Gibel
12/16/2019, 5:21 PMbezrukov
12/16/2019, 5:21 PMAndy Gibel
12/16/2019, 5:21 PMfun getAllSprockets(): List<Sprockets> = runBlocking {
val deferred: Deferred<List<Sprockets>> = async {
repository.getAllSprockets()
}
deferred.await()
}
consider something like this as a public viewmodel interfacegetters
on a VM is an antipatternbezrukov
12/16/2019, 5:43 PMsuspend fun getAllSprockets() = repository.getAllSprockets()
if repository call is suspend fun
or
fun getAllSprockets() = repository.getAllSprockets()
if it blocking
or
suspend fun getAllSprockets() = runBlocking { return repository.getAllSprockets()
}
if repository call is suspend fun, but you need blockingAndy Gibel
12/16/2019, 5:49 PM