Book Image

Learning RxJava

By : Nield
Book Image

Learning RxJava

By: Nield

Overview of this book

RxJava is a library for composing asynchronous and event-based programs using Observable sequences for the JVM, allowing developers to build robust applications in less time. Learning RxJava addresses all the fundamentals of reactive programming to help readers write reactive code, as well as teach them an effective approach to designing and implementing reactive libraries and applications. Starting with a brief introduction to reactive programming concepts, there is an overview of Observables and Observers, the core components of RxJava, and how to combine different streams of data and events together. You will also learn simpler ways to achieve concurrency and remain highly performant, with no need for synchronization. Later on, we will leverage backpressure and other strategies to cope with rapidly-producing sources to prevent bottlenecks in your application. After covering custom operators, testing, and debugging, the book dives into hands-on examples using RxJava on Android as well as Kotlin.
Table of Contents (14 chapters)

Grouping keystrokes

We will wrap up this chapter by integrating most of what we learned and achieve a complex task: grouping keystrokes that happen in rapid succession to form strings without any delay! It can be helpful in user interfaces to immediately "jump" to items in a list based on what is being typed or perform auto-completion in some way. This can be a challenging task, but as we will see, it is not that difficult with RxJava.

This exercise will use JavaFX again with RxJavaFX. Our user interface will simply have a Label that receives rolling concatenations of keys we are typing. But after 300 milliseconds, it will reset and receive an empty  "" to clear it. Here is the code that achieves this as well as some screenshots with the console output when I type "Hello" and then type "World" a moment later:

import io.reactivex.Observable...