Implementing applications that deal with complex concurrent behaviour has always been a challenging aspect of programming. Various paradigms exist that promise a solution to this problem in different ways. RxJava (RxKotlin) is one of them that enables Functional Reactive Programming in Android development. Now Kotlin's concept of suspending function and flow also provides a safer and less error-prone abstraction for asynchronous operations that have similar capabilities to deal with the complex concurrent behaviour. Explore how you can seamlessly migrate from RxJava to Kotlin Coroutines and Flow.
In this coffee break codelab, you'll explore:
-
Overview of RxJava, RxKotlin, Kotlin Coroutine, and Flow
-
Explanation of key concepts based on categories with examples to help for switching from RxJava to Kotlin
-
Comparison based on Reactive type:
RxJava: Example function signature [Observable, Flowable, Single, Maybe, Completable] vs.
Kotlin Flow: Example function signature [Suspend function, Flow]
-
Comparison based on Operators:
RxJava: flatMap, switchMap, and concatMap, Example using flatMap vs.
Kotlin Flow: Example using Suspend function, Flow
-
Comparison based on error handling: RxJava: error handling operators [onErrorReturnItem, onErrorReturn etc] vs.
Kotlin Flow: [try/catch Block, catch builder block]
-
Comparison based on Backpressure handling: RxJava: different types of Strategies to handle backpressure with example vs.
Kotlin Flow: Handling backpressure using a buffer with example