Skip to content

Commit a5edd29

Browse files
committed
Improve performance of SharingStarted.StartedLazily by changing flow to unsafeFlow
1 parent 96de301 commit a5edd29

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Diff for: kotlinx-coroutines-core/common/src/flow/SharingStarted.kt

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
package kotlinx.coroutines.flow
22

33
import kotlinx.coroutines.*
4-
import kotlinx.coroutines.internal.IgnoreJreRequirement
4+
import kotlinx.coroutines.flow.SharingStarted.Companion.Eagerly
5+
import kotlinx.coroutines.flow.SharingStarted.Companion.Lazily
6+
import kotlinx.coroutines.flow.SharingStarted.Companion.WhileSubscribed
7+
import kotlinx.coroutines.flow.internal.*
8+
import kotlinx.coroutines.internal.*
59
import kotlin.time.*
610

711
/**
@@ -146,7 +150,7 @@ private class StartedEagerly : SharingStarted {
146150
}
147151

148152
private class StartedLazily : SharingStarted {
149-
override fun command(subscriptionCount: StateFlow<Int>): Flow<SharingCommand> = flow {
153+
override fun command(subscriptionCount: StateFlow<Int>): Flow<SharingCommand> = unsafeFlow {
150154
var started = false
151155
subscriptionCount.collect { count ->
152156
if (count > 0 && !started) {

0 commit comments

Comments
 (0)