fitken
06/14/2020, 11:14 AMoverride suspend fun getMovieDetails(movieId: Int): LiveData<MovieEntity> {
GlobalScope.launch {
async {
try {
val movieData = mService.getMovieDetails(movieId)
mCache.updateMovie(movieData)
Rose.error("done") // *(2)*
} catch (e: Exception) {
e.printStackTrace()
}
}
}
Rose.error("run first") // *(1)*
return Transformations.map(mCache.getMovie(movieId)) {
return@map MovieEntity(....)
}
}
I want (1) run first, then run (2).
I managed to do that with GlobalScope, but GlobalScope is highly discouraged (I read this here https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-global-scope/index.html)
I also searched on the internet and in this channel with keyword: async suspend function. But haven’t found any answer.
Is there any other way to do that?
Could anyone help me on this? Thank you so much.Zach Klippenstein (he/him) [MOD]
06/14/2020, 4:52 PMfitken
06/15/2020, 1:51 AMfitken
06/15/2020, 4:42 AMfitken
06/15/2020, 10:30 AMZach Klippenstein (he/him) [MOD]
06/15/2020, 3:33 PMliveData
coroutine builder.
https://developer.android.com/topic/libraries/architecture/coroutines#livedatafitken
06/16/2020, 1:03 AMfitken
06/19/2020, 2:37 PM