Hi All, I had a code looks like below
fun main() {
viewModelScope.launch {
doA()
//call api with Flow as the return type
}
}
suspend fun doA() {
viewModelScope.async { doB() }.await()
}
suspend fun doB() {
//Do logic here, eventually will call line below
viewModelScope.launch { doC() }
}
suspend fun doC() {
//call api with Flow as the return type
}
What I want to achieve from the code above is to wait for the
doA()
function to finished and then continue to call the API, but when I tried to run the code, the
doA()
is executed first but it continue to call the API rather than waiting for the
doA()
to finish. Is there's something wrong with the code? Yes, the code is quite bad, I still kind a new with the Coroutine, thanks for helping, really appreciate it