Skip to content

Commit 65b2480

Browse files
committed
update(core): flatMapFirst
1 parent 966f1b7 commit 65b2480

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

core/src/main/java/com/hoc/flowmvi/core/FlowExt.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.hoc.flowmvi.core
22

33
import kotlinx.coroutines.CancellationException
4+
import kotlinx.coroutines.CoroutineStart
45
import kotlinx.coroutines.ExperimentalCoroutinesApi
56
import kotlinx.coroutines.cancel
67
import kotlinx.coroutines.coroutineScope
@@ -48,9 +49,10 @@ fun <T, R> Flow<T>.flatMapFirst(transform: suspend (value: T) -> Flow<R>): Flow<
4849
fun <T> Flow<Flow<T>>.flattenFirst(): Flow<T> = channelFlow {
4950
val outerScope = this
5051
val busy = AtomicBoolean(false)
52+
5153
collect { inner ->
5254
if (busy.compareAndSet(false, true)) {
53-
launch {
55+
outerScope.launch(start = CoroutineStart.UNDISPATCHED) {
5456
try {
5557
inner.collect { outerScope.send(it) }
5658
busy.set(false)

0 commit comments

Comments
 (0)