gildor
04/13/2018, 9:18 AMval first: Deferred<Unit> = async {
firstTask().let { doFirstStuff() }
}
val second: Deferred<Unit> = async {
secondTask().let { doSecondStuff() }
}
first.await()
second.await()
Bjarne Gelotte
04/13/2018, 9:24 AMdoFirstStuff
and doSecondStuff
needs to be done on the UI thread in my case. In this example they will be called on another thread, right?gildor
04/13/2018, 9:31 AMwithContext(UI) { doFirstStuff() }
Bjarne Gelotte
04/13/2018, 9:33 AMlaunch
will be useful. But I wasn't sure if nestled launches
is good/idiomaticgildor
04/13/2018, 9:34 AMlaunch {
val result = firstTask()
withContext(UI) { result.doFirstStuff() }
}
launch {
val result = secondTask()
withContext(UI) { result.doSecondStuff() }
}
Bjarne Gelotte
04/13/2018, 9:38 AMgildor
04/13/2018, 9:39 AMBjarne Gelotte
04/13/2018, 9:40 AM