SlideShare una empresa de Scribd logo
1 de 21
Reactive Programming
Nick Hodge
Developer, Geek
nhodge@mungr.com
http://nickhodge.com/
https://gist.github.com/nickhodge for codesnippets
Who is Nick Hodge?
• 28 years in IT, mostly as non-Developer
• Apple, Adobe, Microsoft
• Many small-scale, rapidly built applications
• Open source contributor
• Functional Reactive Programming Fan
Group Experiment:
Data-at-rest vs. Data-in-motion
• LINQ to IEnumerable (or IQueryable)
• “data at rest”
• yield
• What happens if data changes in midst of foreach() ?
• Reactive programming (IObservable)
• “data in motion”
• Data (or events) are pushed at you
Reactive Programming
demo required
Reactive Programming vs. TPL
• Task Parallel Library (TPL) http://msdn.microsoft.com/en-
us/concurrency
• PLINQ
The core of LINQ
is the sequence
A sequence is just
some stuff in a particular order
What about Rx?
Let’s talk about events
Limitations of .NET Events
exchange.StockTick += (sender, args) =>
{
if (args.Quote.Symbol == “MSFT”)
{
// Imperative code
}
};
exchange.StockTick -= /* what goes here? */;
Observable Sequences to the Rescue
IObservable<Quote> stockQuotes = …;
var msft = stockQuotes
.Where(quote => quote.Symbol == “MSFT”);
var subscription = msft.Subscribe(quote => /* … */);
subscription.Dispose();
Are .NET Events Obsolete?
• .NET Events
• Code centric
• Design-time experience
• Not first class
• Non-compositional
• Lightweight
• Rigid execution model (IL)
• Observables
• Data centric
• No design-time experience
• First class objects
• Rich composition
• Slightly more cost
• Translatable with expression trees
The Event Processing Landscape
Social
media
RSS feeds
GPS
Server management
Reactive Extensions Architecture
Event Streams
• Towards a unified programming model
• Producers are observable sequences
• .NET events, WinRT events, sensor APIs, APM methods, tasks, etc.
• Consumers are observers
• Hooking up “continuations” or handlers
Observable
Subscribe
Observer
Essential Interfaces
namespace System
{
public interface IObservable<out T>
{
IDisposable Subscribe(IObserver<T> observer);
}
public interface IObserver<in T>
{
void OnNext(T value);
void OnError(Exception error);
void OnCompleted();
}
}
Observable Sources
• Single items / empty Observable.Return()
• Lists and arrays
• UI Events
• Async methods
• Subjects (demo)
• Property Changes
Cold / Hot
• Hot : example MouseMove
• Cold: when you subscribe, something happens (it waits)
UI Example, Windows 8 Universal App
This Presentation’s Reference Presentations
• Bart De Smet “Curing Your Event Processing Blues with Reactive
Extensions (Rx)” TechEd Europe 2012
http://channel9.msdn.com/events/TechEd/Europe/2012/DEV413
• Paul Betts “Introduction to Reactive Extensions” Norwegian
Developer’s Conference 2012 http://vimeo.com/43659034
• Brendan Forster “Reactive UI – Turning MVVM up to 11”
http://vimeo.com/97329155
Further References, Links
• https://rx.codeplex.com/ and https://github.com/Reactive-
Extensions/Rx.NET as the starting point
• RxJS (and other languages such as Ruby, C++, Python, Java, ObjC)
https://github.com/Reactive-Extensions/RxJS
• http://www.introtorx.com/
• 101 Rx Examples
http://rxwiki.wikidot.com/101samples
• http://amzn.to/programming-rx “Programming Reactive Extensions
and LINQ”
Further Research, Future
• “Scalable Information Stream Processing by Bing in Support of
Cortana Scenarios” http://channel9.msdn.com/posts/Scalable-
Information-Stream-Processing-by-Bing-in-Support-of-Cortana-
Scenarios
• Actor model, “Microsoft Research project Orleans simplify
development of scalable cloud services”
http://channel9.msdn.com/Shows/Cloud+Cover/Episode-142-
Microsoft-Research-project-Orleans-simplify-development-of-
scalable-cloud-services

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Demystifying Reactive Programming
Demystifying Reactive ProgrammingDemystifying Reactive Programming
Demystifying Reactive Programming
 
Reactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJavaReactive java - Reactive Programming + RxJava
Reactive java - Reactive Programming + RxJava
 
Declarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive ProgrammingDeclarative Concurrency with Reactive Programming
Declarative Concurrency with Reactive Programming
 
Reactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project ReactorReactive Programming In Java Using: Project Reactor
Reactive Programming In Java Using: Project Reactor
 
Introduction to Reactive programming
Introduction to Reactive programmingIntroduction to Reactive programming
Introduction to Reactive programming
 
Project Reactor By Example
Project Reactor By ExampleProject Reactor By Example
Project Reactor By Example
 
Reactive programming - Observable
Reactive programming - ObservableReactive programming - Observable
Reactive programming - Observable
 
Functional reactive programming
Functional reactive programmingFunctional reactive programming
Functional reactive programming
 
Understanding Reactive Programming
Understanding Reactive ProgrammingUnderstanding Reactive Programming
Understanding Reactive Programming
 
Mini-Training: Let's have a rest
Mini-Training: Let's have a restMini-Training: Let's have a rest
Mini-Training: Let's have a rest
 
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin CoroutinesThreading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
Threading Made Easy! A Busy Developer’s Guide to Kotlin Coroutines
 
Quick Tour On Zeppelin
Quick Tour On ZeppelinQuick Tour On Zeppelin
Quick Tour On Zeppelin
 
Introduction to Akka Streams
Introduction to Akka StreamsIntroduction to Akka Streams
Introduction to Akka Streams
 
Flux architecture
Flux architectureFlux architecture
Flux architecture
 
Building Reactive webapp with React/Flux
Building Reactive webapp with React/FluxBuilding Reactive webapp with React/Flux
Building Reactive webapp with React/Flux
 
Flux and React.js
Flux and React.jsFlux and React.js
Flux and React.js
 
Portable Streaming Pipelines with Apache Beam
Portable Streaming Pipelines with Apache BeamPortable Streaming Pipelines with Apache Beam
Portable Streaming Pipelines with Apache Beam
 
Srivalli Aparna - The Blueprints to Success
Srivalli Aparna - The Blueprints to SuccessSrivalli Aparna - The Blueprints to Success
Srivalli Aparna - The Blueprints to Success
 
Prometheus Introduction (InfraCoders Vienna)
Prometheus Introduction (InfraCoders Vienna)Prometheus Introduction (InfraCoders Vienna)
Prometheus Introduction (InfraCoders Vienna)
 
Reactive Streams
Reactive StreamsReactive Streams
Reactive Streams
 

Similar a Reactive programming

Similar a Reactive programming (20)

Quick look in Reactive Extensions
Quick look in Reactive ExtensionsQuick look in Reactive Extensions
Quick look in Reactive Extensions
 
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
 
Rider - Taking ReSharper out of Process
Rider - Taking ReSharper out of ProcessRider - Taking ReSharper out of Process
Rider - Taking ReSharper out of Process
 
Building and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache AirflowBuilding and deploying LLM applications with Apache Airflow
Building and deploying LLM applications with Apache Airflow
 
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
Microservices for building an IDE – The innards of JetBrains Rider - TechDays...
 
Geoscience and Microservices
Geoscience and Microservices Geoscience and Microservices
Geoscience and Microservices
 
Project Flogo: An Event-Driven Stack for the Enterprise
Project Flogo: An Event-Driven Stack for the EnterpriseProject Flogo: An Event-Driven Stack for the Enterprise
Project Flogo: An Event-Driven Stack for the Enterprise
 
Code PaLOUsa Azure IoT Workshop
Code PaLOUsa Azure IoT WorkshopCode PaLOUsa Azure IoT Workshop
Code PaLOUsa Azure IoT Workshop
 
What’s expected in Spring 5
What’s expected in Spring 5What’s expected in Spring 5
What’s expected in Spring 5
 
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems Done "The Simple Way" - Demi Ben-Ari - Codemotion...
 
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...
Monitoring Big Data Systems "Done the simple way" - Demi Ben-Ari - Codemotion...
 
System insight without Interference
System insight without InterferenceSystem insight without Interference
System insight without Interference
 
Unite 2017 - Reactive Programming - Pieter Nijs
Unite 2017 - Reactive Programming - Pieter NijsUnite 2017 - Reactive Programming - Pieter Nijs
Unite 2017 - Reactive Programming - Pieter Nijs
 
Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?Hot to build continuously processing for 24/7 real-time data streaming platform?
Hot to build continuously processing for 24/7 real-time data streaming platform?
 
Dances with bits - industrial data analytics made easy!
Dances with bits - industrial data analytics made easy!Dances with bits - industrial data analytics made easy!
Dances with bits - industrial data analytics made easy!
 
Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"Monitoring Big Data Systems - "The Simple Way"
Monitoring Big Data Systems - "The Simple Way"
 
Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?Has serverless adoption hit a roadblock?
Has serverless adoption hit a roadblock?
 
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
An Open Source Workbench for Prototyping Multimodal Interactions Based on Off...
 
All about that reactive ui
All about that reactive uiAll about that reactive ui
All about that reactive ui
 

Más de Nick Hodge

Virtual #appfest 18th Dec 2012
Virtual #appfest 18th Dec 2012Virtual #appfest 18th Dec 2012
Virtual #appfest 18th Dec 2012
Nick Hodge
 
Victorian principals 17 may2007
Victorian principals 17 may2007Victorian principals 17 may2007
Victorian principals 17 may2007
Nick Hodge
 
Telstra ux presentation 14 dec 2012
Telstra ux presentation 14 dec 2012Telstra ux presentation 14 dec 2012
Telstra ux presentation 14 dec 2012
Nick Hodge
 

Más de Nick Hodge (20)

Virtual #appfest 18th Dec 2012
Virtual #appfest 18th Dec 2012Virtual #appfest 18th Dec 2012
Virtual #appfest 18th Dec 2012
 
Victorian principals 17 may2007
Victorian principals 17 may2007Victorian principals 17 may2007
Victorian principals 17 may2007
 
Telstra ux presentation 14 dec 2012
Telstra ux presentation 14 dec 2012Telstra ux presentation 14 dec 2012
Telstra ux presentation 14 dec 2012
 
Technology and politics digital marketing v5
Technology and politics digital marketing v5Technology and politics digital marketing v5
Technology and politics digital marketing v5
 
Technical windows 8 and windows phone 8 apps
Technical windows 8  and windows phone 8 appsTechnical windows 8  and windows phone 8 apps
Technical windows 8 and windows phone 8 apps
 
Tech ed au 2012 dev223
Tech ed au 2012 dev223Tech ed au 2012 dev223
Tech ed au 2012 dev223
 
Tech ed au 2012 dev212
Tech ed au 2012 dev212Tech ed au 2012 dev212
Tech ed au 2012 dev212
 
SyPy IronPython
SyPy IronPythonSyPy IronPython
SyPy IronPython
 
Stealth PHP on IIS :-)
Stealth PHP on IIS :-)Stealth PHP on IIS :-)
Stealth PHP on IIS :-)
 
Prototyping
PrototypingPrototyping
Prototyping
 
Programming language crisis
Programming language crisisProgramming language crisis
Programming language crisis
 
Popfly mashups for the masses
Popfly mashups for the massesPopfly mashups for the masses
Popfly mashups for the masses
 
Php iis microsoft
Php iis microsoftPhp iis microsoft
Php iis microsoft
 
Osdc php preday odata 2011
Osdc php preday odata 2011Osdc php preday odata 2011
Osdc php preday odata 2011
 
Nsw public sector architects
Nsw public sector architectsNsw public sector architects
Nsw public sector architects
 
Mobile marketing
Mobile marketingMobile marketing
Mobile marketing
 
Microsoft gcio nsw 30 apr2008
Microsoft gcio nsw 30 apr2008Microsoft gcio nsw 30 apr2008
Microsoft gcio nsw 30 apr2008
 
Microsoft and opensource ms ps 2011
Microsoft and opensource ms ps 2011Microsoft and opensource ms ps 2011
Microsoft and opensource ms ps 2011
 
Mah tweets oss wp7
Mah tweets oss wp7Mah tweets oss wp7
Mah tweets oss wp7
 
Jaoo irony
Jaoo ironyJaoo irony
Jaoo irony
 

Último

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
masabamasaba
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
masabamasaba
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
masabamasaba
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
masabamasaba
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
VictoriaMetrics
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
masabamasaba
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Medical / Health Care (+971588192166) Mifepristone and Misoprostol tablets 200mg
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
masabamasaba
 

Último (20)

%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Atlanta Psychic Readings, Attraction spells,Brin...
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
%+27788225528 love spells in new york Psychic Readings, Attraction spells,Bri...
 
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
%+27788225528 love spells in Toronto Psychic Readings, Attraction spells,Brin...
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
%+27788225528 love spells in Knoxville Psychic Readings, Attraction spells,Br...
 
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
%+27788225528 love spells in Boston Psychic Readings, Attraction spells,Bring...
 
Artyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptxArtyushina_Guest lecture_YorkU CS May 2024.pptx
Artyushina_Guest lecture_YorkU CS May 2024.pptx
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
Large-scale Logging Made Easy: Meetup at Deutsche Bank 2024
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
%+27788225528 love spells in Huntington Beach Psychic Readings, Attraction sp...
 
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
%in Rustenburg+277-882-255-28 abortion pills for sale in Rustenburg
 
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
Abortion Pills In Pretoria ](+27832195400*)[ 🏥 Women's Abortion Clinic In Pre...
 
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
%+27788225528 love spells in Colorado Springs Psychic Readings, Attraction sp...
 

Reactive programming

  • 1. Reactive Programming Nick Hodge Developer, Geek nhodge@mungr.com http://nickhodge.com/ https://gist.github.com/nickhodge for codesnippets
  • 2. Who is Nick Hodge? • 28 years in IT, mostly as non-Developer • Apple, Adobe, Microsoft • Many small-scale, rapidly built applications • Open source contributor • Functional Reactive Programming Fan
  • 3. Group Experiment: Data-at-rest vs. Data-in-motion • LINQ to IEnumerable (or IQueryable) • “data at rest” • yield • What happens if data changes in midst of foreach() ? • Reactive programming (IObservable) • “data in motion” • Data (or events) are pushed at you
  • 5. Reactive Programming vs. TPL • Task Parallel Library (TPL) http://msdn.microsoft.com/en- us/concurrency • PLINQ
  • 6. The core of LINQ is the sequence
  • 7. A sequence is just some stuff in a particular order
  • 8. What about Rx? Let’s talk about events
  • 9. Limitations of .NET Events exchange.StockTick += (sender, args) => { if (args.Quote.Symbol == “MSFT”) { // Imperative code } }; exchange.StockTick -= /* what goes here? */;
  • 10. Observable Sequences to the Rescue IObservable<Quote> stockQuotes = …; var msft = stockQuotes .Where(quote => quote.Symbol == “MSFT”); var subscription = msft.Subscribe(quote => /* … */); subscription.Dispose();
  • 11. Are .NET Events Obsolete? • .NET Events • Code centric • Design-time experience • Not first class • Non-compositional • Lightweight • Rigid execution model (IL) • Observables • Data centric • No design-time experience • First class objects • Rich composition • Slightly more cost • Translatable with expression trees
  • 12. The Event Processing Landscape Social media RSS feeds GPS Server management
  • 14. Event Streams • Towards a unified programming model • Producers are observable sequences • .NET events, WinRT events, sensor APIs, APM methods, tasks, etc. • Consumers are observers • Hooking up “continuations” or handlers Observable Subscribe Observer
  • 15. Essential Interfaces namespace System { public interface IObservable<out T> { IDisposable Subscribe(IObserver<T> observer); } public interface IObserver<in T> { void OnNext(T value); void OnError(Exception error); void OnCompleted(); } }
  • 16. Observable Sources • Single items / empty Observable.Return() • Lists and arrays • UI Events • Async methods • Subjects (demo) • Property Changes
  • 17. Cold / Hot • Hot : example MouseMove • Cold: when you subscribe, something happens (it waits)
  • 18. UI Example, Windows 8 Universal App
  • 19. This Presentation’s Reference Presentations • Bart De Smet “Curing Your Event Processing Blues with Reactive Extensions (Rx)” TechEd Europe 2012 http://channel9.msdn.com/events/TechEd/Europe/2012/DEV413 • Paul Betts “Introduction to Reactive Extensions” Norwegian Developer’s Conference 2012 http://vimeo.com/43659034 • Brendan Forster “Reactive UI – Turning MVVM up to 11” http://vimeo.com/97329155
  • 20. Further References, Links • https://rx.codeplex.com/ and https://github.com/Reactive- Extensions/Rx.NET as the starting point • RxJS (and other languages such as Ruby, C++, Python, Java, ObjC) https://github.com/Reactive-Extensions/RxJS • http://www.introtorx.com/ • 101 Rx Examples http://rxwiki.wikidot.com/101samples • http://amzn.to/programming-rx “Programming Reactive Extensions and LINQ”
  • 21. Further Research, Future • “Scalable Information Stream Processing by Bing in Support of Cortana Scenarios” http://channel9.msdn.com/posts/Scalable- Information-Stream-Processing-by-Bing-in-Support-of-Cortana- Scenarios • Actor model, “Microsoft Research project Orleans simplify development of scalable cloud services” http://channel9.msdn.com/Shows/Cloud+Cover/Episode-142- Microsoft-Research-project-Orleans-simplify-development-of- scalable-cloud-services

Notas del editor

  1. We no longer write sync software LINQ: the core of LINQ clojure/Haskell is a sequence (Ienumerable)  things in a particular order MoveNext() MoveNext() Yield/return LINQ : from sequence, and create a pipeline .Select .Where .ForEach (except last, deferred computation)
  2. An order LINQ describe what we are going to do with the data when get it it … without having the data THIS IS A MONAD Monad : chain together functions that describe what you want to do with the data
  3. In the C# world, events are not composable Events are first class elements of the language OnMouseUp + OnMouseDown != OnDoubleClick (delegates) Timer, hook onmouseup/onmousedown, Booleans, state … erg Events fight with different states Event is some stuff in a particular order (time  ) List; happened Events; future or going to happen
  4. Taking what you know about LINQ, applying to events IEnumerable : lists IObservable, stream of events Idisposable, can stop the subscription early. (only if doing early, unless complete on its own) GC will cleanup Iobservable == list, LINQ works .Subscribe is the foreach. Nothing happens until you .Subscribe
  5. .NET event to an observable Special one: Subject<T> push around by hand INotifyPropertyChanged == events