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
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
俺の/私の最強アーキテクチャ決定戦開催 ― チームで新しいアーキテクチャに適合していくために / 20260322 Naoki Takahashi
shift_evolve
PRO
1
450
JEDAI認定プログラム JEDAI Order 2026 受賞者一覧 / JEDAI Order 2026 Winners
databricksjapan
0
370
スピンアウト講座02_ファイル管理
overflowinc
0
1.4k
【PHPerKaigi2026】OpenTelemetry SDKを使ってPHPでAPMを自作する
fendo181
1
300
Zephyr(RTOS)でOpenPLCを実装してみた
iotengineer22
0
110
CloudFrontのHost Header転送設定でパケットの中身はどう変わるのか?
nagisa53
1
190
Phase11_戦略的AI経営
overflowinc
0
1.7k
DDD×仕様駆動で回す高品質開発のプロセス設計
littlehands
6
2.5k
Physical AI on AWS リファレンスアーキテクチャ / Physical AI on AWS Reference Architecture
aws_shota
1
140
Agent Skill 是什麼?對軟體產業帶來的變化
appleboy
0
240
AWS Systems Managerのハイブリッドアクティベーションを使用したガバメントクラウド環境の統合管理
toru_kubota
0
170
「通るまでRe-run」から卒業!落ちないテストを書く勘所
asumikam
2
750
Featured
See All Featured
Designing for humans not robots
tammielis
254
26k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
89
AI Search: Where Are We & What Can We Do About It?
aleyda
0
7.2k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
150
Beyond borders and beyond the search box: How to win the global "messy middle" with AI-driven SEO
davidcarrasco
3
86
Evolving SEO for Evolving Search Engines
ryanjones
0
170
WCS-LA-2024
lcolladotor
0
500
How GitHub (no longer) Works
holman
316
150k
Abbi's Birthday
coloredviolet
2
5.7k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.8k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
First, design no harm
axbom
PRO
2
1.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