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
SingaSUG
July 29, 2015
Technology
0
100
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
180
Migrating to microservices (Carlos Queiroz)
singasug
0
210
Docker 101 - Mario Loriedo
singasug
0
240
Docker for Java/Spring developers
singasug
0
61
Cloud Foundry and Docker
singasug
0
160
Multi dimensional scaling with CouchBase
singasug
1
100
NoSql presentation from Clarence Tauro
singasug
2
170
Spring Websockets
singasug
0
180
migrating from JSP to AngularJS
singasug
0
2.5k
Other Decks in Technology
See All in Technology
FastMCPでSQLをチェックしてくれるMCPサーバーを自作してCursorから動かしてみた
nayuts
1
220
Bill One 開発エンジニア 紹介資料
sansan33
PRO
4
12k
Zero Data Loss Autonomous Recovery Service サービス概要
oracle4engineer
PRO
2
7.2k
Eight Engineering Unit 紹介資料
sansan33
PRO
0
3.2k
Devin&Cursor、それぞれの「本質」から導く最適ユースケース戦略
empitsu
8
2.5k
JNation 2025 - Quarkus for Spring Developers
edeandrea
PRO
0
110
ソフトウェアは捨てやすく作ろう/Let's make software easy to discard
sanogemaru
10
5.8k
データプレーンプログラミングとは? DPU&スイッチASICの開発経験から語る
ebiken
PRO
1
270
kintone開発組織のDevOpsへの移り変わりと実践
ueokande
1
140
MCP Clientを活用するための設計と実装上の工夫
yudai00
1
810
Roo Codeにすべてを委ねるためのルール運用
pharma_x_tech
1
230
いまさら聞けない Git 超入門 〜Gitって結局なに?から始める第一歩〜
devops_vtj
0
170
Featured
See All Featured
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.5k
Rebuilding a faster, lazier Slack
samanthasiow
81
9k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
14
1.5k
Code Review Best Practice
trishagee
68
18k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
1
82
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
129
19k
Thoughts on Productivity
jonyablonski
69
4.7k
Into the Great Unknown - MozCon
thekraken
39
1.8k
The Straight Up "How To Draw Better" Workshop
denniskardys
233
140k
Dealing with People You Can't Stand - Big Design 2015
cassininazir
367
26k
BBQ
matthewcrist
88
9.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
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