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 Streamssterkje
 
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
 
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

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
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...Martijn de Jong
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
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 DevelopmentsTrustArc
 
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...Drew Madelung
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
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 organizationRadu Cotescu
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 

Recently uploaded (20)

Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
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...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
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
 
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...
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 

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