https://kotlinlang.org logo
#rx
Title
# rx
j

Jintin

01/27/2021, 3:52 PM
hi guys, having a question on whether
Single.just
is a hot observable or not. I feel it's not but seems many people think it is. Is there any rule we can follow how to determine it?
z

Zach Klippenstein (he/him) [MOD]

01/27/2021, 4:08 PM
According to this article, it’s hot because the value is produced outside the stream: https://luukgruijs.medium.com/understanding-hot-vs-cold-observables-62d04cf92e03
👀 1
I see where you’re coming from though - I would think of it as cold because all subscribers share the same data stream.
Copy code
val hotSingle = Single.just(1)
vs
Copy code
val coldSingle = Single.fromCallable { 1 }
There’s no distinction if the value you’re emitting is a value type. And even if it isn’t, is this hot or cold?
Copy code
val value = 1
val idkSingle = Single.fromCallable { value }
Given the ambiguity of these terms, and there’s probably even more ways people will interpret them, it’s probably not very helpful to debate the semantics. Just say explicitly what you mean, eg “all observers of this single will see the same value”, or “the value emitted by this single will be created eagerly/upon subscription”.
j

Jintin

01/27/2021, 4:23 PM
I'm not a Rx expert but from http://reactivex.io/documentation/observable.html said, main difference of Hot and Cold I think is
A "hot" Observable may begin emitting items as soon as it is created, and so any observer who later subscribes to that Observable may start observing the sequence somewhere in the middle.
So I feel it's cold as the subscribe didn't affect the value emit and there's no chance to miss the value as well, is it make sense?
👌 3
☝️ 1
z

Zach Klippenstein (he/him) [MOD]

01/27/2021, 5:01 PM
Totally. Every time I see this question I get more convinced that these terms just create confusion more than anything else. There are too many concepts to conflate.
💯 3
4 Views