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

AsyncSubject

The last on the list is the AsyncSubject. It works entirely differently from the previous Subjects because it only emits a single value that it has received from upstream Observables. What it does is that it waits for the upstream Observable to complete, and only then it will emit an item to its subscribers.

Again, let's look at an example:

Subject<String> subject = AsyncSubject.create();Observable.interval(0, 1, TimeUnit.SECONDS)        .take(4)        .map(Objects::toString)        .subscribe(subject);subject.subscribe(v -> log(v));

Here, the upstream Observable is created by this:

Observable.interval(0, 1, TimeUnit.SECONDS)        .take(4)        .map(Objects::toString)

It will issue four items, and it will then complete. After this executes, we will see ...

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