Sobes.tech
Junior — Middle

Kas saab selgitada Cold Observable kontseptsiooni ja kuidas see erineb Hot Observable'ist?

sobes.tech AI

Vastus AI-lt

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 the presence of subscribers. Subscribers only receive data emitted after they subscribe.

Example:

  • Cold Observable — is like a movie recording: each viewer starts watching from the beginning.
  • Hot Observable — is like a live broadcast: if you join later, you'll miss the start.

In RxSwift or RxJava, a cold Observable is created, for example, using Observable.create, and a hot Observable — using Subject or PublishSubject.