O'Reilly logo

Reactive Android Programming by Tadas Subonis

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Concat

.concat() can be used to merge two Observables, as in the following example:

Observable.concat(        Observable.just(1, 2),        Observable.just(3, 4))        .subscribe(v -> log("subscribe", v));

This will yield the given output:

APP: subscribe:main:1APP: subscribe:main:2APP: subscribe:main:3APP: subscribe:main:4

This is not very surprising at all. However, it will be a different case if we execute code like this:

Observable.concat(        Observable.interval(3, TimeUnit.SECONDS),        Observable.just(-1L, -2L))        .subscribe(v -> log("subscribe", v));

.concat() waits for the first Observable to complete before it starts taking values from the second Observable. Since .interval() never completes, the values from the following will never be printed:

 Observable. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required