Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rx Java introduction
Search
Sponsored
·
Ship Features Fearlessly
Turn features on and off without deploys. Used by thousands of Ruby developers.
→
SingaSUG
July 29, 2015
Technology
0
130
Rx Java introduction
Talk from Xavier Lepretre
SingaSUG
July 29, 2015
Tweet
Share
More Decks by SingaSUG
See All by SingaSUG
Java/Spring and Node.JS side by side
singasug
0
210
Migrating to microservices (Carlos Queiroz)
singasug
0
240
Docker 101 - Mario Loriedo
singasug
0
280
Docker for Java/Spring developers
singasug
0
94
Cloud Foundry and Docker
singasug
0
220
Multi dimensional scaling with CouchBase
singasug
1
130
NoSql presentation from Clarence Tauro
singasug
2
200
Spring Websockets
singasug
0
220
migrating from JSP to AngularJS
singasug
0
2.6k
Other Decks in Technology
See All in Technology
Oracle Database@Azure:サービス概要のご紹介
oracle4engineer
PRO
4
1.1k
Claude Codeが爆速進化してプラグイン追従がつらいので半自動化した話 ver.2
rfdnxbro
0
410
Datadog の RBAC のすべて
nulabinc
PRO
2
290
フルカイテン株式会社 エンジニア向け採用資料
fullkaiten
0
10k
EMからVPoEを経てCTOへ:マネジメントキャリアパスにおける葛藤と成長
kakehashi
PRO
9
1.2k
LINE Messengerの次世代ストレージ選定
lycorptech_jp
PRO
19
7.5k
元エンジニアPdM、IDEが恋しすぎてCursorに全業務を集約したら、スライド作成まで爆速になった話
doiko123
1
430
Security Diaries of an Open Source IAM
ahus1
0
200
GitLab Duo Agent Platform + Local LLMサービングで幸せになりたい
jyoshise
0
180
クラウド時代における一時権限取得
krrrr38
1
170
Introduction to Bill One Development Engineer
sansan33
PRO
0
380
Agentic Software Modernization - Back to the Roots (Zürich Agentic Coding and Architectures, März 2026)
feststelltaste
1
200
Featured
See All Featured
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
0
2.4k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
Building a Modern Day E-commerce SEO Strategy
aleyda
45
8.8k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
380
Docker and Python
trallard
47
3.8k
The Cost Of JavaScript in 2023
addyosmani
55
9.7k
<Decoding/> the Language of Devs - We Love SEO 2024
nikkihalliwell
1
150
Fantastic passwords and where to find them - at NoRuKo
philnash
52
3.6k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.8k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
190
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
140
How STYLIGHT went responsive
nonsquared
100
6k
Transcript
RxJava Intro Functional reactive programming By Xavier Lepretre
What we want What we know
Imperative and synchronous var a = fetch(key); var b =
transform(a); var c = transformAgain(b); return process(c);
Asynchronous with callbacks fetch(key, new Callback() { void onReceived(a) {
transform(a, new Callback() { void onFinished(b) ... }); } });
Futures future = executor.submit(new Callback() { Object call() { return
doLongExecution(); } }); a = future.get();
Nice to have, workflow description When done, do that fetch(key).then(a
-> transform(a)) .then(b -> transformAgain(b)) .then(c -> process(c)) .then(d -> use(d));
Important classes
Observable<MyType> - like an object(s) pipe - no limit on
number of objects piped - also pipes Throwable - signals when no more object, completed - can have many observers, like a multicast
Observer<MyType> - will receive: - the objects - the errors
- the completed signal - can subscribe to many observables
Subscription - a handle to an observer subscribed to an
observable - call .unsubscribe() when you no longer need to receive
Action1<MyType> { void call(MyType obj); } - 1 because it
takes 1 parameter - There are Action2 … Action9
Func1<MyType, NextType> { public NextType call(MyType obj); } - 1
because it takes 1 parameter - There are Func2 … Func9
Important operations
.map(new Func1<A,B>(){}) - works on an object traveling along the
pipe - transforms from one type to another - to be used when the transformation is synchronous - example: convert
None
.doOnNext(new Action1<A>(){}) - Works on a object from the pipe
- Leaves the object unchanged - Example: save in cache, log
None
.flatMap(Func1<A, Observable<B>>) - Works on an object traveling along the
pipe - Transforms from one type to another - To be used when the transformation is asynchronous - Example: network fetch, open dialog
None
Advantages - Unsubscription handles removing callback - Method can describe
a subset of workflow
Create your own: OnSubscribe<> - Change callbacks into objects in
pipeline - Know when to call onCompleted() - subscribeOn() - Subscriptions.create() - AndroidSubscriptions. unsubscribeInUiThread
Pitfalls - Forgot to .subscribe() - subscriptionList.unsubscribe(). Do not reuse
- forgot observeOn(AndroidSchedulers. mainThread()) - callbacks may not show as used if you use retrolambda
Code Example https://github.com/xavierlepretre/rx-example
- All code shown is on client - Retrofit creates
Observables -
- workflow pieces in methods: for dialog, no need to
know next step - .onErrorResumeNext() to avoid break on less important elements - .flatMap() to show and wait for dialog - .publish() and .connect() to share Observable - SimpleAlertDialogOperator to convert a dialog into Observable