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
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
SingaSUG
July 29, 2015
Technology
140
0
Share
Rx Java introduction
Talk from Xavier Lepretre
SingaSUG
July 29, 2015
More Decks by SingaSUG
See All by SingaSUG
Java/Spring and Node.JS side by side
singasug
0
220
Migrating to microservices (Carlos Queiroz)
singasug
0
240
Docker 101 - Mario Loriedo
singasug
0
300
Docker for Java/Spring developers
singasug
0
98
Cloud Foundry and Docker
singasug
0
230
Multi dimensional scaling with CouchBase
singasug
1
140
NoSql presentation from Clarence Tauro
singasug
2
210
Spring Websockets
singasug
0
230
migrating from JSP to AngularJS
singasug
0
2.7k
Other Decks in Technology
See All in Technology
oracle-to-databricks-migration-with-llm-and-dbt
casek
0
340
さきさん文庫の書籍ができるまで
sakiengineer
0
300
組織の中で自分を経営する技術
shoota
0
200
GitHub Copilot のこれまでとこれから: From Copilot to Collaborative Agents
yuriemori
1
230
電子辞書Brainをネットに繋げてみた(自力編)
raspython3
0
300
A Harness for Behaviour: how to get AI to generate code that does what we intend, or "TDD in the age of AI"
xpmatteo
0
490
『家族アルバム みてね』における インシデント対応との向き合い方 / Approach incident response in Family Album
kohbis
2
240
Spring Boot における AOT Cache 活用テクニックと 起動時間改善事例
ntt_dsol_java
0
170
最低限これだけ押さえれ大丈夫_Claude Enterprise/Team企業展開ガバナンス入門
tkikuchi
1
440
個人AIからチームAIへ:開発における品質と生産性の再設計
moongift
PRO
0
270
Datadog 認定試験の概要と対策
uechishingo
0
150
Claude Code x Accounting
kawaguti
PRO
1
340
Featured
See All Featured
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.5k
Building AI with AI
inesmontani
PRO
1
1k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
170
Docker and Python
trallard
47
3.9k
Making the Leap to Tech Lead
cromwellryan
135
9.9k
HTML-Aware ERB: The Path to Reactive Rendering @ RubyCon 2026, Rimini, Italy
marcoroth
1
120
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
150
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
370
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
120
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Information Architects: The Missing Link in Design Systems
soysaucechin
0
940
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