Marcin Wisniowski
09/06/2023, 11:31 PMJoffrey
09/06/2023, 11:32 PMsuspend fun <T, R> List<T>.concurrentMap(transform: (T) -> R): List<R> = coroutineScope {
map { async { transform(it) }}.awaitAll()
}
Joffrey
09/06/2023, 11:33 PMJoffrey
09/06/2023, 11:34 PMcoroutineScope
with withContext(Dispatchers.Default)
(or IO, or another multi-threaded dispatcher)Marcin Wisniowski
09/06/2023, 11:35 PMMarcin Wisniowski
09/06/2023, 11:36 PMJoffrey
09/06/2023, 11:36 PMMarcin Wisniowski
09/06/2023, 11:37 PMJoffrey
09/06/2023, 11:38 PMJoffrey
09/06/2023, 11:39 PMasync
and store the `Deferred`s, in the order they were enqueued, in a list of sorts. Then you can await()
them in order.Marcin Wisniowski
09/06/2023, 11:40 PMDeferred
would indeed do what I want! Thanks again. 😄Joffrey
09/06/2023, 11:40 PM