Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Rx Java introduction
Search
SingaSUG
July 29, 2015
Technology
150
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
Transcript
25 slides
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
More Decks by SingaSUG
See All by SingaSUG
Java/Spring and Node.JS side by side
singasug
0
250
Migrating to microservices (Carlos Queiroz)
singasug
0
260
Docker 101 - Mario Loriedo
singasug
0
330
Docker for Java/Spring developers
singasug
0
120
Cloud Foundry and Docker
singasug
0
270
Multi dimensional scaling with CouchBase
singasug
1
170
NoSql presentation from Clarence Tauro
singasug
2
230
Spring Websockets
singasug
0
260
migrating from JSP to AngularJS
singasug
0
2.7k
Other Decks in Technology
See All in Technology
Sonnetだけで業務はまわる?
kintotechdev
1
140
高品質と高スピードを支える品質のシフトレフトのアプローチ
goyoki
4
1.5k
SSFの現在地 ― CAEP/RISCからAI Identityへ
oidfj
0
460
「AIチャットからもできないの?」と言われたら ~業務アプリをMCP対応するときの認証・認可の勘所
oidfj
0
360
BALLAS Technology Deck
ballas_inc
0
780
あの日、見つかっていなかったらどうなっていたか
kazzpapa3
2
240
こんなに変わった! AWSネットワークの常識
shotashiratori
12
8.4k
Frontier Teams — Amazon は AI で「開発のやり方」をどう変えたのか
kmotohas
0
280
田んぼの見回りをIoTで減らしたい!水位監視から電池駆動カメラまでの試行錯誤
itosoft
1
250
文書画像からの情報抽出を行うエージェントを、軌跡の正解データ無しで作れるか
sansantech
PRO
2
160
個人ASを取得して、自宅Kubernetes上のVMをグローバルIPで公開した話
munenick
0
140
これからのデータエンジニアの役割について考える / Rethinking the Role of Data Engineers in the AI Era
okiyuki99
0
530
Featured
See All Featured
Why Your Marketing Sucks and What You Can Do About It - Sophie Logan
marketingsoph
0
470
Become a Pro
speakerdeck
PRO
31
6.4k
Introduction to Domain-Driven Design and Collaborative software design
baasie
1
1.1k
Raft: Consensus for Rubyists
vanstee
143
7.9k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
570
Thoughts on Productivity
jonyablonski
76
5.5k
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
750
For a Future-Friendly Web
brad_frost
184
11k
Reflections from 52 weeks, 52 projects
jeffersonlam
356
22k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
16th Malabo Montpellier Forum Presentation
akademiya2063
PRO
0
460
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k