Introducing the ConnectableObservable object

A great example of Hot Observables is ConnectableObservable. It is one of the most helpful forms of Hot Observables as well. It can turn any Observable, even a Cold Observable, into a Hot Observable. It doesn't start emitting on the subscribe call; instead, it gets activated after you call the connect method. You have to make the subscribe calls before calling connect; any subscribe calls after calling connect will miss the emissions fired previously.

Let's consider the following code snippet:

    fun main(args: Array<String>) { 
      val connectableObservable = listOf      ("String 1","String 2","String 3","String 4","String      5").toObservable() 
      .publish()//1 
      connectableObservable.subscribe({ println ("Subscription ...

Get Reactive Programming in Kotlin now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.