Junior — Middle
Can you explain the concept of Cold Observable and how it differs from Hot Observable?
sobes.tech AI
Answer from AI
Cold Observable is a data stream that starts emitting values only after a subscriber subscribes to it. Each subscriber receives the full set of data from the beginning.
Hot Observable is a stream that emits data regardless of whether there are subscribers. Subscribers only receive data emitted after they subscribe.
Example:
- Cold Observable is like a movie recording: every viewer starts watching from the beginning.
- Hot Observable is like a live broadcast: if you join later, you'll miss the beginning.
In RxSwift or RxJava, a cold Observable is created, for example, using Observable.create, while a hot Observable is created using Subject or PublishSubject.