RxJava is the bane of my existence

seen from Germany
seen from United States
seen from United States
seen from Finland
seen from China

seen from Russia
seen from Finland
seen from United States
seen from United States
seen from Russia
seen from Australia
seen from Netherlands

seen from Bulgaria
seen from United Kingdom
seen from Hong Kong SAR China
seen from United Kingdom

seen from United States
seen from France

seen from United States
seen from Australia
RxJava is the bane of my existence
Lelucon hari ini...
Percakapan antara 2 orang sahabat.
A : [sedang fokus dengan laptopnya]
B : Wih, serius amat nih. Lagi ngapain lo?
A : Mau subscribe..
B : Tumben. Channel mana?
A : Bingung juga. Bagusan milih thread yang mana dulu ya?
B : Hah, maksud lo?
A : Ini nih, untuk project android gua. Lagi nyoba main sama RxJava.
B : asdfghjkl123$&@%'!?
Lelucon hari ini...
Sekarang sedang berlangsung live event pertarungan antara RxJava dan Coroutine Flow di atas ring projek android.
RxJava VS Coroutine
Gelud dimulai
Loading...
Result (?)
Kira-kira siapakah diantara mereka yang akan keluar jadi pemenangnya?
Summary: Stick to whichever library you already have on your CLASSPATH. If you get a choice, Reactor is preferable, RxJava 2.x is ...
It seems Reactor already replaced RxJava.
Difference between Map & Flatmap | RXJava
RXJava can be very intimidating at first go. Reactive Extensions - RX is all about data streams & handling them and three important pillars for it are Observables, Operators & Schedulers.
Initially, while using operators I was very confused between map and flatMap. And this confusion still exists today with all beginners. So let me help you to clear this confusion.
Reactive REST API Using Spring Boot and RxJava https://morioh.com/p/b76e3eb43154 #RxJava #rest #springboot #spring #development
RxAndroid Learnings.
RxAndroid is a library that handles any asynchronous data streams.
What r async data streams:
click event
push notifications
keyboard input
reading a file
database access
device sensor updates
They happen at anytime and outside of normal flow of program execution.
Benefits of Rx:
Chaining
Abstraction
Threading
Non-blocking
Composable
avoid callbacks
data transformation
Function map does data transformation.
Example of Observable with data transformation:
Observable.just( 5, 6, 7 ) .map { “;-) “.repeat(it) } .subscribe { println(it) }
Result:
;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-) ;-)
Example of Observable with chaining:
Observable.just( 5, 6, 7 ) .map { “;-) “.repeat(it) } .filter { it.length < 24 } .subscribe { println(it) }
Result:
;-) ;-) ;-) ;-) ;-)
E.g. kotlin collections
Example:
listOf ( 5, 6, 7 ) .map { it * 5 } .filter { it > 25 }
Process:
5 6 7 map into
25 30 35
filter into
30 35
Disadvantage:
extra overhead
blocking async manner
LAZY - will not create intermediate list with same result.
listOf ( 5, 6, 7 ) .asSequence() .map { it * 5 } .filter { it > 25 } .toList()
RxJava vs Kotlin
in Rx is ok to not have any data initially. Rx is also lazy
Rx has flexible threading model. Can choose thread to do the work on by using Schedulers.
3 Basic of Rx (3o’s)
Observer
Observables
Operators
Observable
U can think of this as producing a stream of events that you are interested in knowing bout.
Observable can be Hot or Cold manner Hot: Start doing work as soon as it gets created. It is not waiting for anyone else before getting “busy”. Example: Click events
Cold: They dont work until someone shows interest. It doesnt work when it gets observable. Example: Reading a file - dont needa do work until someone wants to read a file
Observable.create<Int> { subscriber -> }
Observable.just( item1, item2, item3 )
Observable.interval( 2, TimeUnit.SECODNS )
@Test fun testCreate_withNoSubscriber() {
val observable = Observable.create<Int> { subscriber ->
Logger.log(”create”) subscriber.onNext(4) subscriber.onNext(5) subscriber.onNext(6)
Logger.log(”complete”)
}
Logger.log(”done”) }
================= main: done ================= it only prints “done”
@Test fun testCreate_withSubscriber() {
val observable = Observable.create<Int> { subscriber ->
Logger.log(”create”) subscriber.onNext(4) subscriber.onNext(5) subscriber.onNext(6)
Logger.log(”complete”)
} observable.subscribe { Logger.log( “next: $it” ) }
Logger.log(”done”) }
================= main: create main: next: 4 main: next: 5 main: next: 6 main: complete main: done ================= it only prints “done”
Observer
Observer is the abstraction that Rx java uses for listening to or observing the various items or events that the observable is producing.
interface Observer <T> {
fun onError( e: Throwable )
fun Complete()
fun onNext( t: T )
fun onSubscribe( d: Disposable )
}
Sometimes observer dont rly care bout other things.
interface Consumer <T> { fun accept( t: T ) }
accept method is like the onNext method
Observers: have a lifecycle. Subscribe, Next, Error, Complete
Operator
Operators are what help you to transform and combine / create observable
map()
Observable.just( 5, 6, 7) .map { “ ;-) ”.repeat( it ) } .subscribe { println( it ) }
function map expanded:
flatmap ()
flatmap transform an item into an Observable of different item for long running async task
e.g.
Flowable, Singles, Maybe, BackPressure, Completable, Disposable???
Should you use Rx?
do you like Function programming?
Process items asynchronously?
Compose data?
Handle errors gracefully?
If yes to most of this qns > it depends Rx java can be too complex to handle things u need.
src: https://www.youtube.com/watch?v=YPf6AYDaYf8 useful links: www.adavis.info
Reactive REST API Using Spring Boot and RxJava https://morioh.com/p/b76e3eb43154 #RxJava #rest #springboot #spring #development