ConnectableFlowable
So far, in this chapter, we've dealt with Cold Observables
. What if we want to deal with hot source? Every type of Observable has their counterpart in Flowable. In the previous chapter, we started hot source with ConnectableObservable
, so let's start with ConnectableFlowable
.
As with Observable, ConnectableFlowable
resembles an ordinary Flowable, except that it does not begin emitting items when it is subscribed, but only when its connect()
method is called. In this way, you can wait for all intended Subscribers
to Flowable.subscribe()
, before Flowable
begins emitting items. Please refer to the following code:
fun main(args: Array<String>) { val connectableFlowable = listOf ("String 1","String 2","String 3","String 4", "String 5").toFlowable()//(1) .publish()//(2) connectableFlowable. subscribe({ println("Subscription 1: $it") runBlocking { delay(1000) } println("Subscription 1 delay") ...