Oleg Siboglov
12/24/2019, 4:16 PMwithContext functions since the majority of the use cases require that the code runs sequentially. However, I have one use case where I need to run two of these functions concurrently and then combine the results. My question is if there is would be something wrong with wrapping the withContext functions with an async function.
GlobalScope.launch {
val deferredOne = async { doSomeWork() }
val deferredTwo = async { doSomeWork() }
}
suspend fun doSomeWork() = withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
// Do some work here
}Dominaezzz
12/24/2019, 4:18 PMtseisel
12/24/2019, 11:25 PMcoroutineScope block to make sure that the failure of one will cancel the other (structured concurrency).gildor
12/24/2019, 11:33 PMgildor
12/24/2019, 11:34 PMOleg Siboglov
12/24/2019, 11:38 PM