torres
07/26/2020, 8:35 AMurls.map {
GlobalScope.async { fetchLink(it) }
}.awaitAll().flatMap { it }
versus doing this?
urls.map {
GlobalScope.async { fetchLink(it) }
}.flatMap { it.await() }octylFractal
07/26/2020, 8:36 AMurls is a List, yes -- .awaitAll() will build an extra listoctylFractal
07/26/2020, 8:36 AMGlobalScope here most likelytorres
07/26/2020, 8:37 AMtorres
07/26/2020, 8:37 AMoctylFractal
07/26/2020, 8:38 AMsuspend context:
coroutineScope {
urls.map { async { fetchLink(it) }.flatMap { it.await() }
}
if you're not, replace coroutineScope with runBlocking(Dispatchers.Default)torres
07/26/2020, 8:38 AMurls is a Listtorres
07/26/2020, 8:39 AMoctylFractal
07/26/2020, 8:39 AMasync calls fails, it will cancel all of the other async calls properly, and ensure that exceptions are propagated properlytorres
07/26/2020, 8:41 AMoctylFractal
07/26/2020, 8:42 AMoctylFractal
07/26/2020, 8:42 AMaraqnid
07/27/2020, 4:15 PMawaitAll will fail as soon as one of the fetchLink calls fails, as opposed to only as soon as the fetchLink calls before it in the list have completed/failed
i.e. if the calls are taking a long time, it can make a difference to use awaitAll, as that would propagate a failure sooner (and cancel the siblings)torres
07/28/2020, 8:31 AMtorres
07/28/2020, 8:31 AMasync calls fails, it will cancel all of the other async calls properly, and ensure that exceptions are propagated properly”araqnid
07/28/2020, 8:32 AMoctylFractal
07/28/2020, 8:33 AMawaitAll() had differing behaviorgildor
07/28/2020, 12:48 PMtorres
07/28/2020, 1:35 PMLukas Lechner
07/29/2020, 1:48 PMgildor
07/29/2020, 1:49 PMgildor
07/29/2020, 1:50 PMgildor
07/29/2020, 1:51 PMgildor
07/29/2020, 1:52 PM