elizarov

    elizarov

    3 years ago
    Cold and hot streams? What is the difference and why Kotlin coroutines need both: https://medium.com/@elizarov/cold-flows-hot-channels-d74769805f9
    s

    streetsofboston

    3 years ago
    @elizarov Can Flows be shared/published/ref-counted, to have multiple collections receive the values from the same flow-lambda?
    elizarov

    elizarov

    3 years ago
    Not now, but nothing prevents you (or us) from adding the corresponding feature.
    You can
    publish
    a channel which is analogue of "sharing" it.
    s

    streetsofboston

    3 years ago
    I can't find a function called
    publish
    ... On which class/interface is this defined?
    gildor

    gildor

    3 years ago
    As I understand,
    broadcastIn
    is similar to publish, it converts flow to BroadcastChannel
    sdeleuze

    sdeleuze

    3 years ago
    See my question about hot
    Flow
    https://kotlinlang.slack.com/archives/C1CFAFJSK/p1554801575237600 in #coroutines
    s

    streetsofboston

    3 years ago
    @gildor broadcastIn will start collecting and return a BroadcastChannel. Is there a way to publish/share/ref-count a Flow without collecting and that returns another Flow?
    elizarov

    elizarov

    3 years ago
    You can do
    .asFlow()
    on a broadcast channel
    s

    streetsofboston

    3 years ago
    But a BroadcastChannel is hot.... Is there a way to share a cold Flow and use some sort of subscription/collect counting (much like Rx ref-count) or something like the need to call 'connect', to 'start' the cold Flow?
    elizarov

    elizarov

    3 years ago
    By calling
    connect
    you’ve turned a cold stream into a hot one.
    s

    streetsofboston

    3 years ago
    Yes, but I can subscribe multiple times (like 'collect' in Flow) without making it hot, until it's time to finally call connect. Only then it becomes hot.
    elizarov

    elizarov

    3 years ago
    We don’t have that yet. What is the use-case? Can you please explain in an issue at http://github.com/kotlin/kotlinx.coroutines/issues
    s

    streetsofboston

    3 years ago
    @elizarov I wrote a
    Flow<T>.publish(): ConnectableFlow<T>
    extension-function and its initial implementation seems to work quite well (no thread-safety though). Its use-case is the same as the RxJava’s
    Flowable.publish()
    method. https://gist.github.com/streetsofboston/39c3f8c882c9891b35e0ebc3cd812381 For thing like this, should we also use http://github.com/kotlin/kotlinx.coroutines/issues?
    elizarov

    elizarov

    3 years ago
    Yes. “They have it in RxJava” is not a use-case, though.
    s

    streetsofboston

    3 years ago
    True 😀 I was a bit lazy and just assumed the use-cases of why RxJava has 'publish' were self-evident
    elizarov

    elizarov

    3 years ago
    It is not evident that
    publish
    use-cases need to be solved with
    publish
    operator and don’t have other solutions that should be considered as well
    s

    streetsofboston

    3 years ago
    Absolutely. I’ll open a feature request on the github’s issues list.
    I opened this issue: https://github.com/Kotlin/kotlinx.coroutines/issues/1086 Please be gentle 🙂