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
Intro to reactive programing
Search
Fernando Franco Gíraldez
December 01, 2021
Programming
65
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Intro to reactive programing
Small introduction into rx-java 2.X and it's core element and how to use it
Fernando Franco Gíraldez
December 01, 2021
More Decks by Fernando Franco Gíraldez
See All by Fernando Franco Gíraldez
Design for Developer
ffgiraldez
0
59
Arrow Meta 1o1
ffgiraldez
0
54
Don't Fear the Monads
ffgiraldez
1
170
Reactive your Android
ffgiraldez
1
170
Other Decks in Programming
See All in Programming
一人だけ、Kiroが静止する日
hideg
0
120
Snowflakeで業務アプリを作ろう。 Snowflakeのアプリ機能解説&実践ガイド
ayumu_yamaguchi
1
280
XHTMLが残したもの
yosuke_furukawa
PRO
2
820
テストを司るデーモンに会いに行く 〜隔離した仮想マシンでテストを通すまで〜
h1d3mun3
1
470
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
180
新卒PdEのリアル
ryu1013
1
500
AI活用は、個人から組織へ|マルチプレイヤーエージェントハーネス「QM」の社内活用事例 / AI use is moving from individuals to orgs
rkaga
1
120
cdk deploy JawsSonic #MARATHONしながらAWSリソースをデプロイしてみよう
akihisaikeda
2
140
技術的負債を組織課題として解く-増えすぎたマイクロサービスとの戦い-
reimaru
1
2k
AIは賢い。でも実行環境は? CLIおじさんがAI時代に伝えたいこと ~ CLIおじさんがAI時代に伝えたいこと ~
curekoshimizu
1
250
AI Agent時代のリアーキテクチャ戦略と実践
hokaccha
9
4.8k
モバイル交通系ICへのチャージ実例から考える、クロスプラットフォーム開発におけるiOS実機テスト設計とCI運用
yusuga
1
510
Featured
See All Featured
brightonSEO & MeasureFest 2025 - Christian Goodrich - Winning strategies for Black Friday CRO & PPC
cargoodrich
3
850
ピンチをチャンスに:未来をつくるプロダクトロードマップ #pmconf2020
aki_iinuma
128
56k
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
1
830
Navigating Weather and Climate Data
rabernat
0
520
How People are Using Generative and Agentic AI to Supercharge Their Products, Projects, Services and Value Streams Today
helenjbeal
1
320
Test your architecture with Archunit
thirion
2
2.4k
The browser strikes back
jonoalderson
0
1.7k
Designing for Timeless Needs
cassininazir
1
480
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
56
3.5k
Build The Right Thing And Hit Your Dates
maggiecrowley
39
3.4k
How GitHub (no longer) Works
holman
316
150k
Amusing Abliteration
ianozsvald
1
310
Transcript
Intro To Reactive programing
Schedule ▸ What is reactive programming ▸ Core elements of
rx-java ▸ How to test your reactive chains 2
“ The world has move to push; user are waiting
for us to catch up Lee Campbell - Introduction to Rx
1. What is reactive programing A brief description 4
Mixing of ideas Observable Pattern Iterable Pattern FP style 5
What is reactive programing It’s a library for composing asynchronous
and event based programs by using observable sequences 6
2. Core elements 7
Core elements \ concepts ▸ Observable ▸ Operators ▸ Observer
▸ Disposable ▸ Threading 8
Core elements \ events ▸ onNext ▸ onComplete ▸ onError
9
Core elements \ Observable Observable.create { emitter -> try {
if (!emitter.isDisposed) { emitter.onNext("rxjava FTW!") emitter.onNext("functional programing FTW!") emitter.onComplete() } } catch (exception: Exception) { emitter.onError(exception) } } 10
Core elements \ Observable Observable.create { emitter -> val receiver
= object : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) = emitter.onNext(intent) } context.registerReceiver(receiver, IntentFilter()) emitter.setCancellable { context.unregisterReceiver(receiver) } } 11
Core elements \ Observable \ Specialization ▸ Observable ▸ Single
▸ Completable ▸ Maybe ▸ Flowable 12
Core elements \ Operators 13
Core elements \ Operators 14 networkRequestSingle.map { response -> response.result.name
}
Core elements \ Operators 15 textWatcherObservable.debounce(400, TimeUnit.MILLISECONDS)
Core elements \ Operators 16 suggestionTextWatcher.debounce(400, TimeUnit.MILLISECONDS) .switchMapSingle { repo.searchSuggestion(it)
}
Core elements \ Operators 17 suggestionTextWatcher.doOnNext { loading.postValue(true) } .switchMapSingle
{ repo.searchSuggestion(it) } .doOnSubscribe { loading.postValue(false) }
Core elements \ Observer val observer = object: Observer<String>{ override
fun onNext(t: String) {} override fun onError(e: Throwable) {} override fun onComplete() {} override fun onSubscribe(d: Disposable) {} } 18
Core elements \ Observer suggestionTextWatcher .switchMapSingle { repo.searchSuggestion(it) } .subscribe(observer)
.subscribe { results.postValue(it) } .subscribe({ results -> }, { throwable -> }) .subscribe({ results -> }, { throwable -> }, {}) .subscribeBy( onNext = { results -> }, onError = { throwable -> }, onComplete = {} ) 19
Core elements \ Disposable val disposable = suggestionTextWatcher .subscribe {
results.postValue(it) } disposable.isDisposed() disposable.dispose() val compositeDisposable = CompositeDisposable() disposable.add(suggestionTextWatcher.subscribe{}) disposable.clear() 20
suggestionTextWatcher.switchMapSingle { repo.searchSuggestion(it) } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) Core elements \ Threading
21 To add concurrency into our observable sequence, just indicate to the observable to operate in a particular Scheduler
suggestionTextWatcher.switchMapSingle { repo.searchSuggestion(it) } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) Core elements \ Threading
22 Specify the Scheduler on which an Observable will operate.
suggestionTextWatcher.switchMapSingle { repo.searchSuggestion(it) } .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) Core elements \ Threading
23 Specify the Scheduler on which an Observer will observe this observable.
Testing ▸ How to provide Schedulers? ▸ Make test run
faster ▸ Use black box testing strategies 24
Testing \ Schedulers val testScheduler = TestScheduler() RxJavaPlugins.setIoSchedulerHandler( scheduler ->
testScheduler); RxAndroidPlugins.setMainThreadSchedulerHandler( scheduler -> Schedulers.trampoline()); @field:Rule val testSchedulers = TestSchedulerRule.create(); testScheduler.advanceTimeBy(30, TimeUnit.SECONDS); 25
Testing \ TestObserver Val testObserver = voiceRecognition.observe().test(); testObserver.assertValues(....); testObserver.isTerminated() testObserver.assertSubscribed()
26
27 THANKS! Any questions? @thanerian
[email protected]