February 2020
Intermediate to advanced
412 pages
9h 36m
English
The repeat() operator will repeat subscription after onComplete() a specified number of times. For instance, we can repeat the emissions twice for the given Observable by passing 2 as an argument for repeat(), as shown in the following code snippet:
import io.reactivex.rxjava3.core.Observable;public class Ch3_64 { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma") .repeat(2) .subscribe(s -> System.out.println("Received: " + s)); }}
The output of the preceding code snippet is as follows:
Received: AlphaReceived: BetaReceived: GammaReceived: AlphaReceived: BetaReceived: Gamma
If you do not specify a number, it will repeat infinitely, forever re-subscribing after every onComplete(). There is also a
Read now
Unlock full access