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
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
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
240
Migrating to microservices (Carlos Queiroz)
singasug
0
250
Docker 101 - Mario Loriedo
singasug
0
310
Docker for Java/Spring developers
singasug
0
100
Cloud Foundry and Docker
singasug
0
250
Multi dimensional scaling with CouchBase
singasug
1
150
NoSql presentation from Clarence Tauro
singasug
2
220
Spring Websockets
singasug
0
240
migrating from JSP to AngularJS
singasug
0
2.7k
Other Decks in Technology
See All in Technology
作って理解するCoding Agent 〜フレームワークに頼らないピュア Python での実装〜
takapy
2
140
平文パスワードはログに“残り” ── 肝心の侵入は“痕跡すら残らない”
kuroneko13
0
110
私がブラウザを自作したくなった理由
supurazako
1
280
AI・HPC開発を支えるGPU環境の新しい選択肢 液冷GPUシステム「AquSys」の取り組み
gpuunite_official
0
160
関東Kaggler会発表資料
takoi
1
270
Model Studio CLI × Token Plan
maigo999
0
200
ホームラボ紹介
y_sera15
0
220
8bit CPU 2026
koba789
1
440
Sansan Engineering Unit 紹介資料
sansan33
PRO
1
5k
AI-DLC実践録_フルサイクル開発への挑戦
miyuc
0
320
AIに持続⼒を与える 判断の⻑期記憶設計
eiei114
1
440
Invisible to AI? Making TYPO3 Sites Quotable by AI Search Systems
wolfgangwagner
0
240
Featured
See All Featured
jQuery: Nuts, Bolts and Bling
dougneiner
66
8.5k
Amusing Abliteration
ianozsvald
1
260
Six Lessons from altMBA
skipperchong
29
4.4k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
StorybookのUI Testing Handbookを読んだ
zakiyama
31
6.9k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.7k
Fashionably flexible responsive web design (full day workshop)
malarkey
408
67k
Building an army of robots
kneath
306
46k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
400
How to Think Like a Performance Engineer
csswizardry
28
2.7k
Building a Scalable Design System with Sketch
lauravandoore
463
34k
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