June 2017
Intermediate to advanced
400 pages
8h 44m
English
We can postpone emissions using the delay() operator. It will hold any received emissions and delay each one for the specified time period. If we wanted to delay emissions by three seconds, we could do it like this:
import io.reactivex.Observable;import java.util.concurrent.TimeUnit;public class Launcher { public static void main(String[] args) { Observable.just("Alpha", "Beta", "Gamma" ,"Delta", "Epsilon") .delay(3, TimeUnit.SECONDS) .subscribe(s -> System.out.println("Received: " + s)); sleep(5000); } public static void sleep(long millis) { try { Thread.sleep(millis); } catch (InterruptedException e) { e.printStackTrace(); } }}
The output of the preceding code snippet is as follows:
Received: Alpha Received: Beta Received: Gamma ...
Read now
Unlock full access