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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
SingaSUG
July 29, 2015
Technology
0
120
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
200
Migrating to microservices (Carlos Queiroz)
singasug
0
230
Docker 101 - Mario Loriedo
singasug
0
270
Docker for Java/Spring developers
singasug
0
89
Cloud Foundry and Docker
singasug
0
210
Multi dimensional scaling with CouchBase
singasug
1
130
NoSql presentation from Clarence Tauro
singasug
2
200
Spring Websockets
singasug
0
210
migrating from JSP to AngularJS
singasug
0
2.6k
Other Decks in Technology
See All in Technology
サイボウズ 開発本部採用ピッチ / Cybozu Engineer Recruit
cybozuinsideout
PRO
10
73k
Context Engineeringが企業で不可欠になる理由
hirosatogamo
PRO
3
400
月間数億レコードのアクセスログ基盤を無停止・低コストでAWS移行せよ!アプリケーションエンジニアのSREチャレンジ💪
miyamu
0
800
今日から始めるAmazon Bedrock AgentCore
har1101
4
390
セキュリティについて学ぶ会 / 2026 01 25 Takamatsu WordPress Meetup
rocketmartue
1
290
あたらしい上流工程の形。 0日導入からはじめるAI駆動PM
kumaiu
5
760
制約が導く迷わない設計 〜 信頼性と運用性を両立するマイナンバー管理システムの実践 〜
bwkw
3
860
Meshy Proプラン課金した
henjin0
0
250
CDK対応したAWS DevOps Agentを試そう_20260201
masakiokuda
1
190
20260204_Midosuji_Tech
takuyay0ne
0
100
小さく始めるBCP ― 多プロダクト環境で始める最初の一歩
kekke_n
1
340
~Everything as Codeを諦めない~ 後からCDK
mu7889yoon
3
270
Featured
See All Featured
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
270
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
240
Ethics towards AI in product and experience design
skipperchong
2
190
30 Presentation Tips
portentint
PRO
1
210
The Anti-SEO Checklist Checklist. Pubcon Cyber Week
ryanjones
0
55
The AI Revolution Will Not Be Monopolized: How open-source beats economies of scale, even for LLMs
inesmontani
PRO
3
3k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
31
9.9k
[RailsConf 2023] Rails as a piece of cake
palkan
59
6.3k
Bootstrapping a Software Product
garrettdimon
PRO
307
120k
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.7k
Darren the Foodie - Storyboard
khoart
PRO
2
2.3k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.3k
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