https://kotlinlang.org logo
#feed
Title
# feed
e

elizarov

04/08/2019, 8:21 PM
Cold and hot streams? What is the difference and why Kotlin coroutines need both: https://medium.com/@elizarov/cold-flows-hot-channels-d74769805f9
K 1
👏 6
K 3
👍 32
⏸️ 11
s

streetsofboston

04/08/2019, 8:58 PM
@elizarov Can `Flow`s be shared/published/ref-counted, to have multiple collections receive the values from the same flow-lambda?
e

elizarov

04/08/2019, 9:23 PM
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

04/08/2019, 9:37 PM
I can't find a function called
publish
... On which class/interface is this defined?
g

gildor

04/09/2019, 2:15 AM
As I understand,
broadcastIn
is similar to publish, it converts flow to BroadcastChannel
s

sdeleuze

04/09/2019, 9:20 AM
See my question about hot
Flow
https://kotlinlang.slack.com/archives/C1CFAFJSK/p1554801575237600 in #coroutines
s

streetsofboston

04/09/2019, 11:08 AM
@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?
e

elizarov

04/09/2019, 11:42 AM
You can do
.asFlow()
on a broadcast channel
s

streetsofboston

04/09/2019, 11:52 AM
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?
e

elizarov

04/09/2019, 12:00 PM
By calling
connect
you’ve turned a cold stream into a hot one.
s

streetsofboston

04/09/2019, 12:04 PM
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.
e

elizarov

04/09/2019, 1:37 PM
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
👍 1
s

streetsofboston

04/10/2019, 6:51 PM
@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?
e

elizarov

04/10/2019, 7:07 PM
Yes. “They have it in RxJava” is not a use-case, though.
s

streetsofboston

04/10/2019, 7:44 PM
True 😀 I was a bit lazy and just assumed the use-cases of why RxJava has 'publish' were self-evident
e

elizarov

04/10/2019, 7:48 PM
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

04/10/2019, 7:52 PM
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 🙂
5 Views