If I need a behaviorsubject in the flow world: is ...
# coroutines
p
If I need a behaviorsubject in the flow world: is a ConflatedBroadcastChannel and exposing it as asFlow() the way to go? Or is there a better equivalent?
s
Would this help you for your code? https://github.com/Kotlin/kotlinx.coroutines/issues/1086 This gist is related to that issue: https://gist.github.com/streetsofboston/39c3f8c882c9891b35e0ebc3cd812381 The
fun <T> Flow<T>.cache(scope: CoroutineScope, cacheSize: Int = 1): Flow<T> = replay(cacheSize).autoConnect(scope)
may do what you are looking for.
g
Yes, there is BroadcadtChannel to flow adapter, it should work fine, just exposing flow instead of receivechannel