February 2020
Intermediate to advanced
412 pages
9h 36m
English
The take() operator has two overloaded versions. One takes the specified number of emissions and calls onComplete() after all of them reach it. It will also dispose of the entire subscription so that no more emissions will occur. For instance, take(2) will emit the first two emissions and then call onComplete() (this will generate an onComplete event):
import io.reactivex.rxjava3.core.Observable;public class Ch3_06 { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma") .take(2) .subscribe(s -> System.out.println("RECEIVED: " + s)); }}
The output of the preceding code snippet is as follows:
RECEIVED: AlphaRECEIVED: Beta
Note that if the take() operator receives fewer emissions than specified, it will simply ...
Read now
Unlock full access