Skip to content

Commit fa9dde3

Browse files
committed
[CHORE/#396] 예외처리 구현
1 parent d6d9275 commit fa9dde3

1 file changed

Lines changed: 10 additions & 9 deletions

File tree

  • core/designsystem/src/main/java/com/terning/core/designsystem/extension

core/designsystem/src/main/java/com/terning/core/designsystem/extension/FlowExt.kt

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,17 @@ import kotlinx.coroutines.flow.flow
88

99
fun <T, K> Flow<T>.groupBy(getKey: (T) -> K): Flow<Pair<K, Flow<T>>> = flow {
1010
val storage = mutableMapOf<K, SendChannel<T>>()
11-
12-
collect { t ->
13-
val key = getKey(t)
14-
val channel = storage.getOrPut(key) {
15-
Channel<T>(capacity = Channel.BUFFERED).also {
16-
emit(key to it.consumeAsFlow())
11+
try {
12+
collect { t ->
13+
val key = getKey(t)
14+
val channel = storage.getOrPut(key) {
15+
Channel<T>(capacity = Channel.BUFFERED).also {
16+
emit(key to it.consumeAsFlow())
17+
}
1718
}
19+
channel.send(t)
1820
}
19-
channel.send(t)
21+
} finally {
22+
storage.values.forEach { it.close() }
2023
}
21-
22-
storage.values.forEach { it.close() }
2324
}

0 commit comments

Comments
 (0)