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
Reactive Extensions for JVM
Search
Blaž Šolar
December 21, 2015
Programming
240
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Reactive Extensions for JVM
Blaž Šolar
December 21, 2015
More Decks by Blaž Šolar
See All by Blaž Šolar
Secrets from Google I/O
blazsolar
0
66
Advance Android
blazsolar
0
85
Other Decks in Programming
See All in Programming
Jetpack Compose Mechanisms
skydoves
3
820
C#の現在地 進化の歴史と、AI時代の.NET Everywhere
neuecc
5
5.2k
Herb in Rails 8.2: Your ERB views, now HTML-aware @ Kaigi on Rails 2026, Tokyo, Japan
marcoroth
2
220
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
TechTown - Creating Composable Callables in Contemporary C++
rollbear
0
130
ChromeでローカルLLM
ryu1013
0
140
Compiling a real-world CLI tool to native with Static Hermes
tmikov2023
0
120
ActionController meets Protocol Buffers
sorah
0
520
Next.js: The final boss of Web Performance
guaca
0
250
Starting & Sustaining Code-Based E2E Testing for Non-Coding QA Teams( #jasstniigata )
teyamagu
PRO
1
1k
SREの越境 / SRE Collaboration
y0hgi
2
310
AI主導のプログラミング学習アプリを作ってみた
econanringo
0
180
Featured
See All Featured
Leveraging LLMs for student feedback in introductory data science courses - posit::conf(2025)
minecr
1
440
Groundhog Day: Seeking Process in Gaming for Health
codingconduct
0
410
Un-Boring Meetings
codingconduct
0
460
Become a Pro
speakerdeck
PRO
31
6.3k
The Spectacular Lies of Maps
axbom
PRO
1
1.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
1
750
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.2k
Java REST API Framework Comparison - PWX 2021
mraible
34
9.8k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3.4k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
270
Rails Girls Zürich Keynote
gr2m
96
14k
Transcript
Reactive extensions for JVM
“A library for composing asynchronous and event-based programs using observable
sequences for the JVM” - RxJava
“ReactiveX is a combination of the best ideas from the
Observer pattern, the Iterator pattern, and functional programming” - ReactiveX
Reactive
Problem
Limited method signature public Data getData(); What if the implementation
needs to change from synchronous to asynchronous How should the client execute this method without blocking? Spawn a thread?
Let’s do it async public void getData(Callback<T> c); public Future<T>
getData(); public Future<List<Future<T>>> getData();
Observable push onNext(T) onError(Exception) onCompleted() Iterable vs. Observable Iterable pull
T next() throws Exception returns
Observable push onNext(T) onError(Exception) onCompleted() Iterable pull T next() throws
Exception returns getDataFromLocalMemory() .skip(10) .take(5) .map({ s -> s + "_transformed" }) .forEach({ println "onNext => " + it }) getDataFromNetwork() .skip(10) .take(5) .map({ s -> s + "_transformed" }) .subscribe({ println "onNext => " + it })
How to deal with data Single Multiple Sync T getData();
Iterable<T> getData(); Async Future<T> getData(); Observable<T> getData();
How to deal with data Single Multiple Sync T getData();
Iterable<T> getData(); Async Future<T> getData(); Observable<T> getData(); String s = getData(); if(s.equals(x)) { // do something } else { // do something else }
How to deal with data Single Multiple Sync T getData();
Iterable<T> getData(); Async Future<T> getData(); Observable<T> getData(); Iterable<String> values = getData(); for(String s : values) { if(s.equals(x)) { // do sometinhg } else { // do something else } }
How to deal with data Single Multiple Sync T getData();
Iterable<T> getData(); Async Future<T> getData(); Observable<T> getData(); Future<String> s = getData(); if(s.get().equals(x)) { // do sometinhg } else { // do something else }
How to deal with data Single Multiple Sync T getData();
Iterable<T> getData(); Async Future<T> getData(); Observable<T> getData(); CompletableFuture<String> s = getData(); s.thenAply((v) -> { if(v.equals(x)) { // do something } else { // do something else } })
How to deal with data Single Multiple Sync T getData();
Iterable<T> getData(); Async Future<T> getData(); Observable<T> getData(); Future<String> s = getData(); s.map({ s -> if(s.equals(x)) { // do something } else { // do something else } })
How to deal with data Observable<String> s = getData(); s.map({
s -> if(s.equals(x)) { // do something } else { // do something else } }) Single Multiple Sync T getData(); Iterable<T> getData(); Async Future<T> getData(); Observable<T> getData();
Code examples
Synchronous Observable with single value Observable.create({ observer -> try {
Location location = /** get last location */ observer.onNext(location); observer.onCompleted(); } catch(Exception e) { observer.onError(e); } })
Asynchronous Observable with single value Observable.create({ observer -> executor.execute(new Runnable()
{ def void run() { try { Location location = /** get location */ observer.onNext(location); observer.onCompleted(); } catch(Exception e) { observer.onError(e); } } }) })
Synchronous Observable with multiple values Observable.create({ observer -> try {
for(l in locations) { observer.onNext(l); } observer.onCompleted(); } catch(Exception e) { observer.onError(e); } })
Asynchronous Observable with multiple values Observable.create({ observer -> executor.execute(new Runnable()
{ def void run() { try { for(l in location) { location = /** resolve location */ observer.onNext(location); } observer.onCompleted(); } catch(Exception e) { observer.onError(e); } } }) })
Asynchronous Observer getLocations().subscribe( {location -> prinln "Location: " + location.name
}, { error -> println "Error" }, { println "Completed" } )
Composable functions
Composable functions Transform: map, flatMap, reduce, scan, ... Filter: take,
skip, sample, takeWhile, filter, .... Combine: count, merge, zip, combineLatest, multicast, publish, cache Concurrency: observeOn, subscribeOn Error Handling: onErrorReturn, onErrorResume, ...
Synchronous Observable with single value Observable.create({ observer -> try {
Location location = /** get last location */ observer.onNext(location); observer.onCompleted(); } catch(Exception e) { observer.onError(e); } })
Combining via Merge
Combining via Merge Observable<Data> a = getDataA(); Observable<Data> b =
getDataB(); Observable.merge(a, b) .subscribe( { element -> println "data: " + element})
Combining via Zip
Combining via Merge Observable<Data> a = getDataA(); Observable<String> b =
getDataB(); Observable.zip(a, b, {x, y, -> [x, y]}) .subscribe( { pair -> println "a: " + pair[0] +"b: " + pair[1]})
Error handling Observable<Data> a = getDataA(); Observable<String> b = getDataB();
Observable.zip(a, b, {x, y, -> [x, y]}) .subscribe( { pair -> println "a: " + pair[0] +"b: " + pair[1]}, { exception -> println "Exception " + exception.getMessage})
Error handling
Error handling Observable<Data> a = getDataA(); Observable<String> b = getDataB()
.onErrorResumeNext(getFallbackForB()); Observable.zip(a, b, {x, y, -> [x, y]}) .subscribe( { pair -> println "a: " + pair[0] +"b: " + pair[1]}, { exception -> println "Exception " + exception.getMessage})
Error handling
Thanks!
[email protected]
@solarb