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

2013 06-03 berlin buzzwords
2013 06-03 berlin buzzwords2013 06-03 berlin buzzwords
2013 06-03 berlin buzzwords
Nitay 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 Group
Nitay Joffe
 
Storm distributed processing
Storm distributed processingStorm distributed processing
Storm distributed processing
ducquoc_vn
 
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
Morten Andersen-Gott
 
Introduction to Storm
Introduction to Storm Introduction to Storm
Introduction to Storm
Chandler Huang
 

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

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

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