Hot and Cold Observable: RxJava

val coldObservable : Observable<String> =
Observable.just("1", "2", "3", "4")
.doOnComplete {
Log.e(TAG, "Completed emitting streams")
}
// First observer
val firstObserver= coldObservable.subscribe {
Log.d(TAG," observer 1 receveied: = $it")
}
// second Observerval secondObserver= coldObservable.subscribe {
Log.d(TAG," observer 2 receveied: = $it")
}
//hot observable example
val hotObservable = Observable.interval(1, TimeUnit.SECONDS)
.doOnComplete {
Log.e(TAG, "Completed emitting streams")
}.publish()
hotObservable.connect()
val firstObserver = hot.subscribe {
Log.e(TAG," observer 1 receveied: = $it")
}
Thread.sleep(3000);val secondObserver = hot.subscribe {
Log.e(TAG," observer 2 receveied: = $it")
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Gaurav Rajput

Gaurav Rajput

Working remotely as Android Developer