bobby
11/11/2020, 10:17 AMfun 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 itNaoki Hidaka
11/11/2020, 10:57 AMbobby
11/11/2020, 10:58 AMNaoki Hidaka
11/11/2020, 11:00 AMfun main() {
viewModelScope.launch {
async { doA() }.await
}
}
bobby
11/11/2020, 11:02 AMfun main() {
viewModelScope.launch {
async { doB() }.await()
}
}
Naoki Hidaka
11/11/2020, 11:02 AMbobby
11/11/2020, 11:03 AMbobby
11/12/2020, 2:10 AMdoA()
which is the call API still run without waiting the doA()
finish. I think because at the doB()
I created new scope that I think works separate with the scope in main()