October 2018
Intermediate to advanced
556 pages
15h 18m
English
RxJava makes it possible to generate not only one event in the future, but an asynchronous sequence of events based, for example, on a time interval, as shown in the following code:
Observable.interval(1, TimeUnit.SECONDS) .subscribe(e -> System.out.println("Received: " + e));Thread.sleep(5000); // (1)
In that case, the output is as following:
Received: 0Received: 1Received: 2Received: 3Received: 4
Also, if we remove Thread.sleep(...) (1), our application will exit without any output. This happens because events would be generated and therefore consumed in a separate daemon thread. So, to prevent the main thread from finishing the execution, we may sleep() or do some other useful tasks.
Of course, there ...
Read now
Unlock full access