February 2020
Intermediate to advanced
412 pages
9h 36m
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 3 seconds, we could do it like this:
import io.reactivex.rxjava3.core.Observable;import java.util.concurrent.TimeUnit;public class Ch3_63 { public static void main(String[] args) { DateTimeFormatter f = DateTimeFormatter.ofPattern("MM:ss"); System.out.println(LocalDateTime.now().format(f)); Observable.just("Alpha", "Beta", "Gamma") .delay(3, TimeUnit.SECONDS) .subscribe(s -> System.out.println(LocalDateTime.now() .format(f) + " Received: " + s)); sleep(5000); }}
The output of the preceding code snippet is as follows (the first column is the current time of the ...
Read now
Unlock full access