SlideShare a Scribd company logo
1 of 9
Rx – Reactive Extensions for .NET
Jakub Malý
Rx – Intro
• Why? Event handling is too hard…
• Is it really?
– Adobe’s Sean Parent [1]:
• 1/3 of the code in Adobe’s desktop applications
is devoted to event handling logic
• 1/2 of the bugs reported during a product cycle
exist in this code
• Aiming at
– push-based scenarios
– event handling
– Asynchronicity
[1] http://stlab.adobe.com/wiki/images/0/0c/Possible_future.pdf
Rx – Observables
• Rx = Observables + LINQ + Schedulers
• IObservable is something similarly fundamental as IEnumerable
– they are in fact DUAL concepts
• IEnumerable = pull based, synchronous - foreach blocks
• IObservable = push based - subscribing does not block
IObservable<T> - provider for push-based notifications
IDisposable Subscribe(IObserver<T> observer)
IObserver<T> - mechanism for receiving push-based notifications
void OnNext(T value)
void OnError(Exception error)
void OnCompleted()
Observables vs. Events - usage
public event Action<String> Change;
public void Load()
{
Change += OnChange;
}
private void OnChange(string s)
{
// event occurred
}
public void DoThings()
{
var tmp = Change;
tmp("Hello!");
}
public Subject<string> Change;
public void Load()
{
Change.Subscribe(OnNext);
}
private void OnNext(string s)
{
// new value observed
}
public void DoThings()
{
Change.OnNext("Hello!");
}
Observables vs. Events - differences
• Events
– delegates with some
sugar
– pushing is easy
– (un)subscribing less easy
– no support for
manipulation
• how to raise an event
in a different thread?
– We never know it’s
“done”
– operators += and -=
• Observables
– first class citizens
• passing around as
parameters, variables
– support operators
• LINQ
• combinations
– can be scheduled, run in
a specific context
(designated thread,
thread pool)
– Subscribe,
subscription.Dispose
Where to get Observables?
• (implement the interface)
• Predefined implementations: Subject<T>
• Use factories:
– Observable primitives (Throw, Return, Empty, Never)
– Observable.Create(…), Observable.Generate()
– IEnumerable<T>.ToObservalbe()
– Observable.FromEvent(…)
– Observable.FromAsync(…)
– “Special” observables: Range, Interval, Timer, Repeat..
– Querying, manipulating and combining existing
observables
Schedulers
• Observables can be created or parameterized
by schedulers
• “Context” where messages are handled
• Can introduce asynchronicity
• Usage:
– Subscription runs in a designated thread (e.g. to
utilize NUMA)
– Use thread pool to increase throughput
– Pass handling to UI thread
Reactive programming
• a programming paradigm - close to functional
paradigm (pursuit to abstract state - LINQ)
• synchronous programming : everything takes
time, but time is ignored
• focus on
– flows of inputs during the lifetime of the program
(user/UI, services, messages, cloud...)
– responsiveness, asynchronicity, notion of time
• variables don't capture values, but definitions of
future input flows
References
• http://rx.codeplex.com
• Chanel9
– Rx: Curing your asynchronous programming blues
– Rx workshop
• Intro to Rx (online book):
http://www.introtorx.com/
• Maier, Rompf, Odersky: Deprecating the
observer pattern

More Related Content

Similar to Rx- Reactive Extensions for .NET

Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examplesPeter Lawrey
 
2013 06-03 berlin buzzwords
2013 06-03 berlin buzzwords2013 06-03 berlin buzzwords
2013 06-03 berlin buzzwordsNitay Joffe
 
2013.09.10 Giraph at London Hadoop Users Group
2013.09.10 Giraph at London Hadoop Users Group2013.09.10 Giraph at London Hadoop Users Group
2013.09.10 Giraph at London Hadoop Users GroupNitay Joffe
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorStéphane Maldini
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & designallegro.tech
 
AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly
AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly
AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly SolarWinds Loggly
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaYardena Meymann
 
Storm distributed processing
Storm distributed processingStorm distributed processing
Storm distributed processingducquoc_vn
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Evan Chan
 
Workshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive StreamsWorkshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive StreamsKristof Van Sever
 
Workshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive StreamsWorkshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive Streamssterkje
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigoujaxconf
 
Parallel batch processing with spring batch slideshare
Parallel batch processing with spring batch   slideshareParallel batch processing with spring batch   slideshare
Parallel batch processing with spring batch slideshareMorten Andersen-Gott
 
Introduction to Storm
Introduction to Storm Introduction to Storm
Introduction to Storm Chandler Huang
 
How to Monitor Microservices
How to Monitor MicroservicesHow to Monitor Microservices
How to Monitor MicroservicesSysdig
 
Data Pipelines with Python - NWA TechFest 2017
Data Pipelines with Python - NWA TechFest 2017Data Pipelines with Python - NWA TechFest 2017
Data Pipelines with Python - NWA TechFest 2017Casey Kinsey
 
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016jtmelton
 

Similar to Rx- Reactive Extensions for .NET (20)

Mini training - Reactive Extensions (Rx)
Mini training - Reactive Extensions (Rx)Mini training - Reactive Extensions (Rx)
Mini training - Reactive Extensions (Rx)
 
Reactive programming with examples
Reactive programming with examplesReactive programming with examples
Reactive programming with examples
 
2013 06-03 berlin buzzwords
2013 06-03 berlin buzzwords2013 06-03 berlin buzzwords
2013 06-03 berlin buzzwords
 
2013.09.10 Giraph at London Hadoop Users Group
2013.09.10 Giraph at London Hadoop Users Group2013.09.10 Giraph at London Hadoop Users Group
2013.09.10 Giraph at London Hadoop Users Group
 
Springone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and ReactorSpringone2gx 2014 Reactive Streams and Reactor
Springone2gx 2014 Reactive Streams and Reactor
 
RxJava - introduction & design
RxJava - introduction & designRxJava - introduction & design
RxJava - introduction & design
 
AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly
AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly
AWS re:Invent presentation: Unmeltable Infrastructure at Scale by Loggly
 
Writing Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & AkkaWriting Asynchronous Programs with Scala & Akka
Writing Asynchronous Programs with Scala & Akka
 
Storm distributed processing
Storm distributed processingStorm distributed processing
Storm distributed processing
 
Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015Akka in Production - ScalaDays 2015
Akka in Production - ScalaDays 2015
 
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje CrnjakJavantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
Javantura v3 - Going Reactive with RxJava – Hrvoje Crnjak
 
Workshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive StreamsWorkshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive Streams
 
Workshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive StreamsWorkshop: Event-sourced system through Reactive Streams
Workshop: Event-sourced system through Reactive Streams
 
The Road to Lambda - Mike Duigou
The Road to Lambda - Mike DuigouThe Road to Lambda - Mike Duigou
The Road to Lambda - Mike Duigou
 
Parallel batch processing with spring batch slideshare
Parallel batch processing with spring batch   slideshareParallel batch processing with spring batch   slideshare
Parallel batch processing with spring batch slideshare
 
Introduction to Storm
Introduction to Storm Introduction to Storm
Introduction to Storm
 
How to Monitor Microservices
How to Monitor MicroservicesHow to Monitor Microservices
How to Monitor Microservices
 
Data Pipelines with Python - NWA TechFest 2017
Data Pipelines with Python - NWA TechFest 2017Data Pipelines with Python - NWA TechFest 2017
Data Pipelines with Python - NWA TechFest 2017
 
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
Building Self-Defending Applications With OWASP AppSensor JavaOne 2016
 
OpenStack 101
OpenStack 101OpenStack 101
OpenStack 101
 

Recently uploaded

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 

Recently uploaded (20)

My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 

Rx- Reactive Extensions for .NET

  • 1. Rx – Reactive Extensions for .NET Jakub Malý
  • 2. Rx – Intro • Why? Event handling is too hard… • Is it really? – Adobe’s Sean Parent [1]: • 1/3 of the code in Adobe’s desktop applications is devoted to event handling logic • 1/2 of the bugs reported during a product cycle exist in this code • Aiming at – push-based scenarios – event handling – Asynchronicity [1] http://stlab.adobe.com/wiki/images/0/0c/Possible_future.pdf
  • 3. Rx – Observables • Rx = Observables + LINQ + Schedulers • IObservable is something similarly fundamental as IEnumerable – they are in fact DUAL concepts • IEnumerable = pull based, synchronous - foreach blocks • IObservable = push based - subscribing does not block IObservable<T> - provider for push-based notifications IDisposable Subscribe(IObserver<T> observer) IObserver<T> - mechanism for receiving push-based notifications void OnNext(T value) void OnError(Exception error) void OnCompleted()
  • 4. Observables vs. Events - usage public event Action<String> Change; public void Load() { Change += OnChange; } private void OnChange(string s) { // event occurred } public void DoThings() { var tmp = Change; tmp("Hello!"); } public Subject<string> Change; public void Load() { Change.Subscribe(OnNext); } private void OnNext(string s) { // new value observed } public void DoThings() { Change.OnNext("Hello!"); }
  • 5. Observables vs. Events - differences • Events – delegates with some sugar – pushing is easy – (un)subscribing less easy – no support for manipulation • how to raise an event in a different thread? – We never know it’s “done” – operators += and -= • Observables – first class citizens • passing around as parameters, variables – support operators • LINQ • combinations – can be scheduled, run in a specific context (designated thread, thread pool) – Subscribe, subscription.Dispose
  • 6. Where to get Observables? • (implement the interface) • Predefined implementations: Subject<T> • Use factories: – Observable primitives (Throw, Return, Empty, Never) – Observable.Create(…), Observable.Generate() – IEnumerable<T>.ToObservalbe() – Observable.FromEvent(…) – Observable.FromAsync(…) – “Special” observables: Range, Interval, Timer, Repeat.. – Querying, manipulating and combining existing observables
  • 7. Schedulers • Observables can be created or parameterized by schedulers • “Context” where messages are handled • Can introduce asynchronicity • Usage: – Subscription runs in a designated thread (e.g. to utilize NUMA) – Use thread pool to increase throughput – Pass handling to UI thread
  • 8. Reactive programming • a programming paradigm - close to functional paradigm (pursuit to abstract state - LINQ) • synchronous programming : everything takes time, but time is ignored • focus on – flows of inputs during the lifetime of the program (user/UI, services, messages, cloud...) – responsiveness, asynchronicity, notion of time • variables don't capture values, but definitions of future input flows
  • 9. References • http://rx.codeplex.com • Chanel9 – Rx: Curing your asynchronous programming blues – Rx workshop • Intro to Rx (online book): http://www.introtorx.com/ • Maier, Rompf, Odersky: Deprecating the observer pattern