ubu
12/01/2020, 1:45 PMfun someFun() {
val job1 = viewModelScope.launch { operation1() }
val job2 = viewModelScope.launch { operation2() }
}
Are these two operations sequential by default? Operation in the first launch block is completed, and only then, the second operation is started.Jon Michael Aanes
12/01/2020, 1:53 PMrtsketo
12/01/2020, 1:58 PMchristophsturm
12/01/2020, 2:03 PMShalom Halbert
12/01/2020, 4:25 PMMain
dispatcher from different `CoroutineScope`s (e.g. two `viewModelScope`s) are indirectly run sequentially because the work will run on the UI thread. It’s worth noting that the work does not start immediately, unlike if you were to run the work outside of a CoroutineScope
.
Please correct me if that’s wrong.Chris Ruddell
12/01/2020, 5:03 PMscope.launch {
someUiCall()
withContext(<http://Dispatchers.IO|Dispatchers.IO>) { someNetworkCall() }
someUiCall()
}
So two launch blocks called on the Main scope won’t necessarily be run sequentiallyubu
12/02/2020, 9:51 AMviewModelScope.launch {
operation1()
operation2()
}
suspend fun operation1() { … }
suspend fun operation2() { … }
in this case, will operations be executed sequentially?christophsturm
12/02/2020, 9:52 AM