June 2017
Intermediate to advanced
400 pages
8h 44m
English
The take() operator has two overloads. One will take a specified number of emissions and then call onComplete() after it captures all of them. It will also dispose of the entire subscription so that no more emissions will occur. For instance, take(3) will emit the first three emissions and then call the onComplete() event:
import io.reactivex.Observable;public class Launcher { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma", "Delta", "Epsilon") .take(3) .subscribe(s -> System.out.println("RECEIVED: " + s)); }}
The output of the preceding code snippet is as follows:
RECEIVED: Alpha RECEIVED: Beta RECEIVED: Gamma
Note that if you receive fewer emissions than you specify in your take() function, it ...
Read now
Unlock full access