SlideShare una empresa de Scribd logo
1 de 35
Reactive Extensions for .Net Scott Weinstein Principal Lab49 weblogs.asp.net/sweinstein   / @ScottWeinstein
What is it? The Reactive Extensions for .Net are a new API from MS Dev labs to enable “Linq over Events” Why should I care? Offers a better programming model then Events
Some Concepts
Please sir, can I have some more?
Bid 20, bid 20.2, bid 20.8,…
Pull For pull, data is processed at the leisure of the consumer.  The consumer “pulls” the next item from the producer Common examples include: reading from a file summing the numbers in an array iterating though a database query traversing a directory listing paging through an Amazon search
Push	 For push, data is send via demands of the source.  The producer pushes the data to the consumer. Common examples include: Device measurements such as time light  heat User triggered data such as  Mouse & Keyboard events UI events Sales transactions Asynchronous code
Push & Pull In both scenarios, data moves from the producer to the consumer
Push & Pull in .Net In .Net Pulled data is exposed via common interface pair IEnumerable/IEnumerator There is no other way Foreach and Linq are build on these interfaces Pushed data is exposed via Events Ad-hoc delegate callbacks Ad-hoc subscribe/callback interfaces BeginXXX/EndXXX Async pattern 3rd party attempts at Linq for Pushed data (Clinq,Slinq,PushLinq) Each implementation is unique is its own special way
LINQ LINQprovides a composable and standard way to do list manipulations The Reactive Extensions (RX) attempt to Provide a common interface for Pushed data IObservable/IObserver Enable Linq over Pushed data, providing composiblity and standard operators
DemoSimple Temperature Alerts
Events to Observables Demo
Func and Action and Lambdas Func<int> a; Func<int,int,int> add = (a,b) => a+b; Action<T> t; Action <T,T> tt;
Some (Category) Theory There is a formal basis for the RX Duality, as such, is the assertion that truth is invariant under this operation on statements. In other words, if a statement is true about C, then its dual statement is true about Cop. Also, if a statement is false about C, then its dual has to be false about Cop. Informally, these conditions state that the dual of a statement is formed by reversing arrows and compositions. What this means is that if we can create a Dual of IEnumerable then all of Linq will work over pushed data
Dualizing IEnumerator interface IEnumerator<T>  {     T Current { get; } // but can throw an exception     bool MoveNext();     void Reset(); // not used } Reverse the arrows interface IObserverDraft1<T>  {     SetCurrent(T value); // but need to handle an exception     MoveNext(bool can) ; }
Dualizing IEnumerator (2/2) interface IObserverDraft2<T> {     OnNext(T value);      OnError(Exception ex);     MoveNext(bool can) ; //but called every time! } interface IObserver<T>  {     OnNext(T value);      OnError(Exception ex);     OnCompleted(); // only called once }
Dualizing IEnumerable interface IEnumerable<T>  {     IEnumerator<T> GetEnumerator(); } Reverse the arrows public interface IObservableDraft1<T>  { // But how do I stop observing?     SetObserver(IObserver<T> obs);  }
Dualizing IEnumerable (2/2) interface IObservableDraft2<T>  {     Subscribe(IObserver<T> obs); // can I be more composable?     Unsubscribe(IObserver<T> obs);  } interface IObservable<T>  {     IDisposable Subscribe(IObserver<T> obs); }
Terse functional explanation Enumerable: () –> (() –> Option<T>) FuncEnumerable<T> –> 		Func<Func<Option<T>>> Observable (Option<T> –> ()) –> () FuncObservable<T> –> 			Action<Action<Option<T>>>
Combinators Demo  Implement Where()
Some useful Combinators CombineLatest Do ForkJoin GroupBy Scan HoldUntilChanged Interval Merge ObserveOnDispatcher Sample Throttle Select SelectMany Where Zip
How to create Observables? Create CreateWithDisposable FromAsyncPattern FromEvent Generate ISubject In general, it’s a mistake to create custom implementations of IObservable or IObserver When might it be ok to break this rule?
Streaming OLAP Demo Scan, GroupBy, Where, Zip, Merge, SelectMany
Merge IObservable<T> a IObservable<T> b A.Merge(B) == IObservable<T> ==
Zip IObservable<T> a IObservable<Y> b a.Zip(b, selector) == IObservable<Z> ==
Grouping IObservable<T> IGroupedObservable<TKey, TElement> Key IObservable<IGroupedObservable<Tkey,TElement>> KeyA KeyB KeyC
Hot & Cold Observables (and Enumerables) come in two flavors Hot Values exist outside of subscription Cold Value only exist because of subscription Cold observables can be prone to side-effects ToArray() is one method for making cold Enumerables hot, Replay() and Publish for Observables (and now Enumerables)
Hot and Cold Demo
Code vs. Data RX has an alternate method of representing stream events Interface defines a code-centric view OnNext OnError OnCompleted Notification defines a data-centric view new Notification<T>.OnNext(T next) Where is this useful?
Schedulers RX introduces Schedulers for explicit control  Which thread do subscriptions run on How is time represented ControlSchedulerCurrentThreadScheduler DispatcherSchedulerImmediateScheduler NewThreadSchedulerSynchronizationContextScheduler TaskPoolSchedulerThreadPoolScheduler
Topics not covered Joins Subjects  combine Observability and Enumerablility into a single class.  BehaviorSubject<T> AsyncSubject<T> ReplaySubject<T> Subject<T>
How to get it? Download from the DevLabs: Reactive Extensions for .NET (Rx) site .Net 4 In .Net 4 – IObservable/IObserver are part of the BCL .Net 3.5 SP1 Silverlight 3 Javascript Current license is “go-live” however the API is still evolving
Resources Reactive Extensions for .Net Forums Videos http://weblogs.asp.net/sweinstein
Delayed Expensive Search
DemoAsync webpage download

Más contenido relacionado

La actualidad más candente

Javascript function
Javascript functionJavascript function
Javascript functionLearningTech
 
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14Abu Saleh
 
Get Functional on the CLR: Intro to Functional Programming with F#
Get Functional on the CLR: Intro to Functional Programming with F# Get Functional on the CLR: Intro to Functional Programming with F#
Get Functional on the CLR: Intro to Functional Programming with F# David Alpert
 
Computer Science Programming Assignment Help
Computer Science Programming Assignment HelpComputer Science Programming Assignment Help
Computer Science Programming Assignment HelpProgramming Homework Help
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notationMuthiah Abbhirami
 
07 Retrieving Objects
07 Retrieving Objects07 Retrieving Objects
07 Retrieving ObjectsRanjan Kumar
 
Electrical Engineering Exam Help
Electrical Engineering Exam HelpElectrical Engineering Exam Help
Electrical Engineering Exam HelpLive Exam Helper
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Beyond lists - Copenhagen 2015
Beyond lists - Copenhagen 2015Beyond lists - Copenhagen 2015
Beyond lists - Copenhagen 2015Phillip Trelford
 
Docase notation for Haskell
Docase notation for HaskellDocase notation for Haskell
Docase notation for HaskellTomas Petricek
 
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Philip Schwarz
 

La actualidad más candente (20)

Pointer to function 2
Pointer to function 2Pointer to function 2
Pointer to function 2
 
Erlang Quick Start
Erlang Quick StartErlang Quick Start
Erlang Quick Start
 
Javascript function
Javascript functionJavascript function
Javascript function
 
Rx workshop
Rx workshopRx workshop
Rx workshop
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14Lecture 4, c++(complete reference,herbet sheidt)chapter-14
Lecture 4, c++(complete reference,herbet sheidt)chapter-14
 
This pointer
This pointerThis pointer
This pointer
 
Reactive fsharp
Reactive fsharpReactive fsharp
Reactive fsharp
 
Get Functional on the CLR: Intro to Functional Programming with F#
Get Functional on the CLR: Intro to Functional Programming with F# Get Functional on the CLR: Intro to Functional Programming with F#
Get Functional on the CLR: Intro to Functional Programming with F#
 
Computer Science Programming Assignment Help
Computer Science Programming Assignment HelpComputer Science Programming Assignment Help
Computer Science Programming Assignment Help
 
Data structures and Big O notation
Data structures and Big O notationData structures and Big O notation
Data structures and Big O notation
 
07 Retrieving Objects
07 Retrieving Objects07 Retrieving Objects
07 Retrieving Objects
 
Unit 6 pointers
Unit 6   pointersUnit 6   pointers
Unit 6 pointers
 
Electrical Engineering Exam Help
Electrical Engineering Exam HelpElectrical Engineering Exam Help
Electrical Engineering Exam Help
 
C++ programming function
C++ programming functionC++ programming function
C++ programming function
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
Beyond lists - Copenhagen 2015
Beyond lists - Copenhagen 2015Beyond lists - Copenhagen 2015
Beyond lists - Copenhagen 2015
 
Complexity
ComplexityComplexity
Complexity
 
Docase notation for Haskell
Docase notation for HaskellDocase notation for Haskell
Docase notation for Haskell
 
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
Game of Life - Polyglot FP - Haskell - Scala - Unison - Part 3
 

Destacado

Distribute Process Knowledge in Adaptive Case management through Mentoring
Distribute Process Knowledge in Adaptive Case management through MentoringDistribute Process Knowledge in Adaptive Case management through Mentoring
Distribute Process Knowledge in Adaptive Case management through MentoringAdaPro GmbH
 
Adaptive Case Management as a Process of Construction of and Movement in a St...
Adaptive Case Management as a Process of Construction of and Movement in a St...Adaptive Case Management as a Process of Construction of and Movement in a St...
Adaptive Case Management as a Process of Construction of and Movement in a St...Ilia Bider
 
Tqm chaos and complexity
Tqm chaos and complexityTqm chaos and complexity
Tqm chaos and complexityAhmed Moussa
 
Reactive Programming in .Net - actorbased computing with Akka.Net
Reactive Programming in .Net - actorbased computing with Akka.NetReactive Programming in .Net - actorbased computing with Akka.Net
Reactive Programming in .Net - actorbased computing with Akka.NetSören Stelzer
 
Case Management: Where Rules Meet Process And Content
Case Management: Where Rules Meet Process And ContentCase Management: Where Rules Meet Process And Content
Case Management: Where Rules Meet Process And ContentSandy Kemsley
 
A Case for Declarative Process Modelling - Slides on Adaptive Case Managment ...
A Case for Declarative Process Modelling - Slides on Adaptive Case Managment ...A Case for Declarative Process Modelling - Slides on Adaptive Case Managment ...
A Case for Declarative Process Modelling - Slides on Adaptive Case Managment ...Thomas Hildebrandt
 
Reactive applications with Akka.Net - DDD East Anglia 2015
Reactive applications with Akka.Net - DDD East Anglia 2015Reactive applications with Akka.Net - DDD East Anglia 2015
Reactive applications with Akka.Net - DDD East Anglia 2015Anthony Brown
 
History of Management
History of ManagementHistory of Management
History of ManagementGPERI
 
Adapting to case management
Adapting to case managementAdapting to case management
Adapting to case managementTom Shepherd
 
Taylorism and Fayolism
Taylorism and FayolismTaylorism and Fayolism
Taylorism and FayolismJunesh Acharya
 
scientific management by taylor and fayolism- Administrative management(theor...
scientific management by taylor and fayolism- Administrative management(theor...scientific management by taylor and fayolism- Administrative management(theor...
scientific management by taylor and fayolism- Administrative management(theor...Reon Zedval
 
Taming The Unpredictable: Real-World Adaptive Case Management
Taming The Unpredictable: Real-World Adaptive Case ManagementTaming The Unpredictable: Real-World Adaptive Case Management
Taming The Unpredictable: Real-World Adaptive Case ManagementKeith Swenson
 

Destacado (13)

Distribute Process Knowledge in Adaptive Case management through Mentoring
Distribute Process Knowledge in Adaptive Case management through MentoringDistribute Process Knowledge in Adaptive Case management through Mentoring
Distribute Process Knowledge in Adaptive Case management through Mentoring
 
Adaptive Case Management as a Process of Construction of and Movement in a St...
Adaptive Case Management as a Process of Construction of and Movement in a St...Adaptive Case Management as a Process of Construction of and Movement in a St...
Adaptive Case Management as a Process of Construction of and Movement in a St...
 
Tqm chaos and complexity
Tqm chaos and complexityTqm chaos and complexity
Tqm chaos and complexity
 
Reactive Programming in .Net - actorbased computing with Akka.Net
Reactive Programming in .Net - actorbased computing with Akka.NetReactive Programming in .Net - actorbased computing with Akka.Net
Reactive Programming in .Net - actorbased computing with Akka.Net
 
Case Management: Where Rules Meet Process And Content
Case Management: Where Rules Meet Process And ContentCase Management: Where Rules Meet Process And Content
Case Management: Where Rules Meet Process And Content
 
A Case for Declarative Process Modelling - Slides on Adaptive Case Managment ...
A Case for Declarative Process Modelling - Slides on Adaptive Case Managment ...A Case for Declarative Process Modelling - Slides on Adaptive Case Managment ...
A Case for Declarative Process Modelling - Slides on Adaptive Case Managment ...
 
Reactive applications with Akka.Net - DDD East Anglia 2015
Reactive applications with Akka.Net - DDD East Anglia 2015Reactive applications with Akka.Net - DDD East Anglia 2015
Reactive applications with Akka.Net - DDD East Anglia 2015
 
History of Management
History of ManagementHistory of Management
History of Management
 
Adapting to case management
Adapting to case managementAdapting to case management
Adapting to case management
 
Taylorism and Fayolism
Taylorism and FayolismTaylorism and Fayolism
Taylorism and Fayolism
 
scientific management by taylor and fayolism- Administrative management(theor...
scientific management by taylor and fayolism- Administrative management(theor...scientific management by taylor and fayolism- Administrative management(theor...
scientific management by taylor and fayolism- Administrative management(theor...
 
Introduction to BPM
Introduction to BPMIntroduction to BPM
Introduction to BPM
 
Taming The Unpredictable: Real-World Adaptive Case Management
Taming The Unpredictable: Real-World Adaptive Case ManagementTaming The Unpredictable: Real-World Adaptive Case Management
Taming The Unpredictable: Real-World Adaptive Case Management
 

Similar a Intro to RX

Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Datagreenwop
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++ppd1961
 
Windows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best PracticesWindows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best PracticesSriram Krishnan
 
MarGotAspect - An AspectC++ code generator for the mARGOt framework
MarGotAspect - An AspectC++ code generator for the mARGOt frameworkMarGotAspect - An AspectC++ code generator for the mARGOt framework
MarGotAspect - An AspectC++ code generator for the mARGOt frameworkLeonardo Arcari
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimizedWoody Pewitt
 
Presen 179
Presen 179Presen 179
Presen 179s1140179
 
닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기YoungSu Son
 
Peaberry - Blending Services And Extensions
Peaberry - Blending Services And ExtensionsPeaberry - Blending Services And Extensions
Peaberry - Blending Services And ExtensionsStuart McCulloch
 
Toub parallelism tour_oct2009
Toub parallelism tour_oct2009Toub parallelism tour_oct2009
Toub parallelism tour_oct2009nkaluva
 
Real-World Pulsar Architectural Patterns
Real-World Pulsar Architectural PatternsReal-World Pulsar Architectural Patterns
Real-World Pulsar Architectural PatternsDevin Bost
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Pythongturnquist
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And AnswerJagan Mohan Bishoyi
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answerlavparmar007
 
overloading in C++
overloading in C++overloading in C++
overloading in C++Prof Ansari
 

Similar a Intro to RX (20)

Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++Generalized Functors - Realizing Command Design Pattern in C++
Generalized Functors - Realizing Command Design Pattern in C++
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
 
C#, What Is Next?
C#, What Is Next?C#, What Is Next?
C#, What Is Next?
 
Windows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best PracticesWindows Azure - Cloud Service Development Best Practices
Windows Azure - Cloud Service Development Best Practices
 
MarGotAspect - An AspectC++ code generator for the mARGOt framework
MarGotAspect - An AspectC++ code generator for the mARGOt frameworkMarGotAspect - An AspectC++ code generator for the mARGOt framework
MarGotAspect - An AspectC++ code generator for the mARGOt framework
 
Is your C# optimized
Is your C# optimizedIs your C# optimized
Is your C# optimized
 
Presen 179
Presen 179Presen 179
Presen 179
 
닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기닷넷 개발자를 위한 패턴이야기
닷넷 개발자를 위한 패턴이야기
 
Peaberry - Blending Services And Extensions
Peaberry - Blending Services And ExtensionsPeaberry - Blending Services And Extensions
Peaberry - Blending Services And Extensions
 
Toub parallelism tour_oct2009
Toub parallelism tour_oct2009Toub parallelism tour_oct2009
Toub parallelism tour_oct2009
 
Saving lives with rx java
Saving lives with rx javaSaving lives with rx java
Saving lives with rx java
 
Lecture 3 c++
Lecture 3 c++Lecture 3 c++
Lecture 3 c++
 
First Look at Pointers
First Look at PointersFirst Look at Pointers
First Look at Pointers
 
Real-World Pulsar Architectural Patterns
Real-World Pulsar Architectural PatternsReal-World Pulsar Architectural Patterns
Real-World Pulsar Architectural Patterns
 
Intro To Spring Python
Intro To Spring PythonIntro To Spring Python
Intro To Spring Python
 
C++ Interview Question And Answer
C++ Interview Question And AnswerC++ Interview Question And Answer
C++ Interview Question And Answer
 
C++ questions And Answer
C++ questions And AnswerC++ questions And Answer
C++ questions And Answer
 
Von neumann workers
Von neumann workersVon neumann workers
Von neumann workers
 
overloading in C++
overloading in C++overloading in C++
overloading in C++
 

Último

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...apidays
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Angeliki Cooney
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProduct Anonymous
 
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 FresherRemote DBA Services
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FMESafe Software
 
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, Adobeapidays
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Jeffrey Haguewood
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
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...DianaGray10
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Victor Rentea
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdfSandro Moreira
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 

Último (20)

Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
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
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
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...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 

Intro to RX

  • 1. Reactive Extensions for .Net Scott Weinstein Principal Lab49 weblogs.asp.net/sweinstein / @ScottWeinstein
  • 2. What is it? The Reactive Extensions for .Net are a new API from MS Dev labs to enable “Linq over Events” Why should I care? Offers a better programming model then Events
  • 4. Please sir, can I have some more?
  • 5. Bid 20, bid 20.2, bid 20.8,…
  • 6. Pull For pull, data is processed at the leisure of the consumer. The consumer “pulls” the next item from the producer Common examples include: reading from a file summing the numbers in an array iterating though a database query traversing a directory listing paging through an Amazon search
  • 7. Push For push, data is send via demands of the source. The producer pushes the data to the consumer. Common examples include: Device measurements such as time light heat User triggered data such as Mouse & Keyboard events UI events Sales transactions Asynchronous code
  • 8. Push & Pull In both scenarios, data moves from the producer to the consumer
  • 9. Push & Pull in .Net In .Net Pulled data is exposed via common interface pair IEnumerable/IEnumerator There is no other way Foreach and Linq are build on these interfaces Pushed data is exposed via Events Ad-hoc delegate callbacks Ad-hoc subscribe/callback interfaces BeginXXX/EndXXX Async pattern 3rd party attempts at Linq for Pushed data (Clinq,Slinq,PushLinq) Each implementation is unique is its own special way
  • 10. LINQ LINQprovides a composable and standard way to do list manipulations The Reactive Extensions (RX) attempt to Provide a common interface for Pushed data IObservable/IObserver Enable Linq over Pushed data, providing composiblity and standard operators
  • 13. Func and Action and Lambdas Func<int> a; Func<int,int,int> add = (a,b) => a+b; Action<T> t; Action <T,T> tt;
  • 14. Some (Category) Theory There is a formal basis for the RX Duality, as such, is the assertion that truth is invariant under this operation on statements. In other words, if a statement is true about C, then its dual statement is true about Cop. Also, if a statement is false about C, then its dual has to be false about Cop. Informally, these conditions state that the dual of a statement is formed by reversing arrows and compositions. What this means is that if we can create a Dual of IEnumerable then all of Linq will work over pushed data
  • 15. Dualizing IEnumerator interface IEnumerator<T> { T Current { get; } // but can throw an exception bool MoveNext(); void Reset(); // not used } Reverse the arrows interface IObserverDraft1<T> { SetCurrent(T value); // but need to handle an exception MoveNext(bool can) ; }
  • 16. Dualizing IEnumerator (2/2) interface IObserverDraft2<T> { OnNext(T value); OnError(Exception ex); MoveNext(bool can) ; //but called every time! } interface IObserver<T> { OnNext(T value); OnError(Exception ex); OnCompleted(); // only called once }
  • 17. Dualizing IEnumerable interface IEnumerable<T> { IEnumerator<T> GetEnumerator(); } Reverse the arrows public interface IObservableDraft1<T> { // But how do I stop observing? SetObserver(IObserver<T> obs); }
  • 18. Dualizing IEnumerable (2/2) interface IObservableDraft2<T> { Subscribe(IObserver<T> obs); // can I be more composable? Unsubscribe(IObserver<T> obs); } interface IObservable<T> { IDisposable Subscribe(IObserver<T> obs); }
  • 19. Terse functional explanation Enumerable: () –> (() –> Option<T>) FuncEnumerable<T> –> Func<Func<Option<T>>> Observable (Option<T> –> ()) –> () FuncObservable<T> –> Action<Action<Option<T>>>
  • 20. Combinators Demo Implement Where()
  • 21. Some useful Combinators CombineLatest Do ForkJoin GroupBy Scan HoldUntilChanged Interval Merge ObserveOnDispatcher Sample Throttle Select SelectMany Where Zip
  • 22. How to create Observables? Create CreateWithDisposable FromAsyncPattern FromEvent Generate ISubject In general, it’s a mistake to create custom implementations of IObservable or IObserver When might it be ok to break this rule?
  • 23. Streaming OLAP Demo Scan, GroupBy, Where, Zip, Merge, SelectMany
  • 24. Merge IObservable<T> a IObservable<T> b A.Merge(B) == IObservable<T> ==
  • 25. Zip IObservable<T> a IObservable<Y> b a.Zip(b, selector) == IObservable<Z> ==
  • 26. Grouping IObservable<T> IGroupedObservable<TKey, TElement> Key IObservable<IGroupedObservable<Tkey,TElement>> KeyA KeyB KeyC
  • 27. Hot & Cold Observables (and Enumerables) come in two flavors Hot Values exist outside of subscription Cold Value only exist because of subscription Cold observables can be prone to side-effects ToArray() is one method for making cold Enumerables hot, Replay() and Publish for Observables (and now Enumerables)
  • 28. Hot and Cold Demo
  • 29. Code vs. Data RX has an alternate method of representing stream events Interface defines a code-centric view OnNext OnError OnCompleted Notification defines a data-centric view new Notification<T>.OnNext(T next) Where is this useful?
  • 30. Schedulers RX introduces Schedulers for explicit control Which thread do subscriptions run on How is time represented ControlSchedulerCurrentThreadScheduler DispatcherSchedulerImmediateScheduler NewThreadSchedulerSynchronizationContextScheduler TaskPoolSchedulerThreadPoolScheduler
  • 31. Topics not covered Joins Subjects combine Observability and Enumerablility into a single class. BehaviorSubject<T> AsyncSubject<T> ReplaySubject<T> Subject<T>
  • 32. How to get it? Download from the DevLabs: Reactive Extensions for .NET (Rx) site .Net 4 In .Net 4 – IObservable/IObserver are part of the BCL .Net 3.5 SP1 Silverlight 3 Javascript Current license is “go-live” however the API is still evolving
  • 33. Resources Reactive Extensions for .Net Forums Videos http://weblogs.asp.net/sweinstein