We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
mapOnSuspend
awaitAll
1 parent 0ab1acb commit 135092eCopy full SHA for 135092e
core-android/src/main/java/com/pluu/utils/coroutines/mapOnSuspend.kt
@@ -1,10 +1,11 @@
1
package com.pluu.utils.coroutines
2
3
import kotlinx.coroutines.async
4
+import kotlinx.coroutines.awaitAll
5
import kotlinx.coroutines.coroutineScope
6
7
// 참고 1. https://github.com/Kotlin/coroutines-examples/blob/master/examples/suspendingSequence/suspendingSequence.kt
8
// 참고 2. https://jivimberg.io/blog/2018/05/04/parallel-map-in-kotlin/
9
suspend fun <A, B> Iterable<A>.mapOnSuspend(f: suspend (A) -> B): List<B> = coroutineScope {
- map { async { f(it) } }.map { it.await() }
10
+ map { async { f(it) } }.awaitAll()
11
}
0 commit comments