Go Reactive Manuel Vicente Vivo @manuelvicnt
Go Reactive
Manuel Vicente Vivo
@manuelvicnt
What is Reactive Programming?
Go Reactive @manuelvicnt
Programming paradigm based on
Propagation of changes
Processing data flows
Can be used in a Functional style
Propagation of Changes
Processing Data Flows
Output of processing the different flows
Source A
Source B Source B Modified
FUNCTIONAL REACTIVE
LAMBDAS
CLOSURES
COMPOSABLE
PUSH
EVENTS
ASYNCHRONOUS
@manuelvicnt Go Reactive
Reactive Extensions
C#: Rx.NET
Java: RxJava
JavaScript: RxJS
Scala: RxScala
Swift: RxSwift
C++: RxCpp
Ruby: Rx.rb
Python: RxPY
Groovy: RxGroovy
Kotlin: RxKotlin
Android: RxAndroid
iOS: RxCocoa
Go Reactive @manuelvicnt
RxJava http://github.com/Netflix/RxJava
“ A library for COMPOSING ASYNCHRONOUS and event-based
programs using OBSERVABLE SEQUENCES for the Java VM”
Go Reactive @manuelvicnt
Components
Go Reactive @manuelvicnt
Observables: Emit Items
Subscribers: Consume Items
Common Methods: onNext
onCompleted
onError
Subscribers
Go Reactive @manuelvicnt
Consume items
Observables
Go Reactive @manuelvicnt
Emit items
Subjects
Go Reactive @manuelvicnt
Are both an Observable and a Subscriber
Operators http://rxmarbles.com
Go Reactive @manuelvicnt
Transformers map, flatMap
Filters filter, take, skip
Conditions takeWhile
Combination concat, zip
Aggregate count, toList
Go Reactive @manuelvicnt
Observable
Observable
Map Operator Observable
Zip Operator
Observable seen by the Subscriber
Backpressure
Go Reactive @manuelvicnt
The Observable is too fast for Subscribers
Can happen anywhere in the chain
Operators: Throttle
Debounce
Testing Observables
Go Reactive @manuelvicnt
Create special cases
Observable.error()
Observable.empty()
Observable.never()
Use TestSubscriber
Live Coding https://github.com/manuelvicnt/RxJava-android-structure
Fragments Subscribers
View Models Subjects
Registration API Service Observable
UserData Request Manager
Observable
Login API Service Observable
Account API Service Observable
Games API Service Observable
Authentication Request Manager
Observable
Retrofit Registration
Retrofit Login
Retrofit Account
Retrofit Games
Go Reactive @manuelvicnt
1. Registration Retrofit returns
Observable
2. Registration API Service propagates the
Observable
3. User Auth RM concatenates Login Request
4. User Auth RM gets the Login Observable
5. Subscribers will get this when subscribing to Registration,
Registration & Login request will be made and the result will be a
Login Response
Go Reactive @manuelvicnt
1.1 Account Data from Account API Service
Observable
3. Subscriber will get the result
when both requests come
2. Zip Operator in UserData RM Observable
1.2 Games Data from Games API Service
Observable