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
130
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
290
Docker for Java/Spring developers
singasug
0
97
Cloud Foundry and Docker
singasug
0
220
Multi dimensional scaling with CouchBase
singasug
1
140
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
2026年、知っておくべき最新 サーバレスTips10選/serverless-10-tips
slsops
12
4.7k
🀄️ on swiftc
giginet
PRO
0
360
ふりかえりがなかった職能横断チームにふりかえりを導入してみて学んだこと 〜チームのふりかえりを「みんなで未来を考える場」にするプロローグ設計〜
masahiro1214shimokawa
0
400
Databricksで構築するログ検索基盤とアーキテクチャ設計
cscengineer
0
190
Code Interpreter で、AIに安全に コードを書かせる。
yokomachi
0
5.9k
BigQuery × dbtでコスト削減した話
rightcode
0
140
NgRx SignalStore: The Power of Extensibility
rainerhahnekamp
0
230
Databricksを用いたセキュアなデータ基盤構築とAIプロダクトへの応用.pdf
pkshadeck
PRO
0
330
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
最新の脅威動向から考える、コンテナサプライチェーンのリスクと対策
kyohmizu
0
110
【Findy FDE登壇_2026_04_14】— 現場課題を本気で解いてたら、FDEになってた話
miyatakoji
0
1.1k
Azure PortalなどにみるWebアクセシビリティ
tomokusaba
0
260
Featured
See All Featured
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
710
Building a A Zero-Code AI SEO Workflow
portentint
PRO
0
440
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.1k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
35
2.4k
Prompt Engineering for Job Search
mfonobong
0
260
Side Projects
sachag
455
43k
The B2B funnel & how to create a winning content strategy
katarinadahlin
PRO
1
330
Balancing Empowerment & Direction
lara
6
1k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.1k
How to Ace a Technical Interview
jacobian
281
24k
Music & Morning Musume
bryan
47
7.1k
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