Skip to content

Commit 135092e

Browse files
committed
Refactor, mapOnSuspend to use awaitAll
1 parent 0ab1acb commit 135092e

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
package com.pluu.utils.coroutines
22

33
import kotlinx.coroutines.async
4+
import kotlinx.coroutines.awaitAll
45
import kotlinx.coroutines.coroutineScope
56

67
// 참고 1. https://github.com/Kotlin/coroutines-examples/blob/master/examples/suspendingSequence/suspendingSequence.kt
78
// 참고 2. https://jivimberg.io/blog/2018/05/04/parallel-map-in-kotlin/
89
suspend fun <A, B> Iterable<A>.mapOnSuspend(f: suspend (A) -> B): List<B> = coroutineScope {
9-
map { async { f(it) } }.map { it.await() }
10+
map { async { f(it) } }.awaitAll()
1011
}

0 commit comments

Comments
 (0)