Learning RxJava

Learning RxJava

Title Page
About the Author
About the Reviewers
Customer Feedback

Understanding backpressure

Throughout this book, I emphasized the "push-based" nature of Observables. Pushing items synchronously and one at a time from the source all the way to the Observer is indeed how Observable chains work by default without any concurrency.

For instance, the following is an Observable that will emit the numbers 1 through 999,999,999. It will map each integer to a MyItem instance, which simply holds it as a property. But let's slow down the processing of each emission by 50 milliseconds in the Observer. This shows that even if the downstream is slowly processing each emission, the upstream synchronously keeps pace with it. This is because one thread is doing all the work:

 import io.reactivex.Observable;

 public class Launcher {

     public static void main(String[] args) {

         Observable.range(1, 999_999_999)
                 .subscribe(myItem -> {
Unlock full access

Continue reading with a subscription

Packt gives you instant online access to a library of over 7,500 practical eBooks and videos, constantly updated with the latest in tech

Your notes and bookmarks