Concatenating producers (Observable/Flowable)

Concatenating operators are almost the same with merge operators, except that the concatenating operators respect the prescribed ordering. Instead of subscribing to all provided producers in one go, it subscribes to the producers one after another; only once, it received onComplete from the previous subscription.

So, let's modify our last program with the concatenate operator and see the changes:

    fun main(args: Array<String>) { 
      val observable1 = Observable.interval(500, TimeUnit.MILLISECONDS) 
        .take(2)//(1) 
        .map { "Observable 1 $it" }//(2) 
      val observable2 = Observable.interval(100, TimeUnit.MILLISECONDS).map { "Observable 2 $it" }//(3) Observable .concat(observable1,observable2) .subscribe { println("Received ...

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.