This document discusses push and pull data processing paradigms and introduces the Reactive Extensions (Rx) library. It notes that in a pull paradigm, data is processed at the leisure of the destination, while in a push paradigm data is processed based on source demands. The document then explains that Rx provides a common interface (IObservable/IObserver) to work with push data and enable LINQ-style query operations. It provides examples of Observables and Observers and discusses various Rx operators and capabilities.
2. Multiple data items can be “processed” in either
a push or a pull fashion.
In a pull paradigm, data is processed at the
leisure of the destination. 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
3. In a push paradigm, data is processed via
demands of the source. Common examples
include:
Device measurements such as
time
light
heat
User triggered data such as
Mouse & Keyboard events
UI events
Sales transactions
Asynchronous code
4. In .Net Pulled data is exposed via a single core
interface
IEnumerable/IEnumerator
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 it’s own way
5. LINQ provides 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
6. Available for free from Domains
MS DevLabs Events
http://bit.ly/reext APM
Support for Web service calls
.Net 3.5 SP1 Async workflows
.Net 4 Task<T>-based calls
Silverlight 3 Applications
JavaScript Web page d/l
Not part of .Net 4 :( Async file IO
Except the interfaces Streaming OLAP
7. 5 assemblies (including
PFX) System.CoreEx
Feel free to ILmerge
Main features
System.Interactive
Interfaces (IObserver<T>,
IObservable<T>) System.Observable
Observer conversions
LINQ support System.Reactive
WinForms & WPF
notification support System.Threading (PFX)
Infrastructure
No particular namespace
8. Implemented by the object that wants to
receive notifications
OnNext(T value)
Called when a value has been provided
OnError(Exception ex)
Called in case of an error
OnCompleted()
When done
The contract is
OnNext* (OnError|OnCompleted)
9. Implemented by an object which can be
observed
IDisposable Subscribe(
IObserver<T> obs);
Called by the observer to subscribe
Typical behavior
Adds each observer to a List<IObserver<T>>
Calls OnXxx() on each listed observer
Dispose() called to unsubscribe
More composable – no need for Unsubscribe()
10. Typically, you would not implement these
interfaces
Use helper methods to get Observable<T>
Use Subscribe() to act as an Observer<T>
Observable.FromEvent()
Observable.FromAsyncPattern()
EnumerableEx.ToObservable()
Enumerable → Observable
Observable.Interval
Generates an event in an interval
11. Observable.FromXxx lets you create an
anonymous observable
Subscribe() lets you create an anonymous
observer
Parameters take
An IObserver<T>
A combination of Action<T>’s that correspond to
OnNext, OnError and OnCompleted
12.
13. New LINQ combinators Amb
Time CombineLatest
Presence/absence Delay
Value changes
Repeat
Value patterns
Utility TakeUntil/TakeWhile
SkipUntil/SkipWhile
Mirrored in IEnumerable Scan
EnumerableEx Timer
Using
14. Scan CombineLatest
Yields running aggregate Combines each pair of
values latest values
list = { 1, 2, 3 };
o.Scan((a,b) => a+b)
yields
1, 3, 6
15. Merge Zip
Collates two streams into Pairwise collection of
one items in stream
16.
17. How observables produce values even when
not subscribed
var timer = new Timer(1000);
var hot = Observable.FromEvent(
timer, “Elapsed”);
Cold observable produces values onl y on
subscriptions
var cold = Obsevable.Interval(
TimeSpan.FromSeconds(1));
18. Rx itself http://bit.ly/reext
Rx Team Blog http://blogs.msdn.com/RxTeam/
Lots of Rx videos
Rx PowerToys
http://rxpowertoys.codeplex.com/
Tracing
Time machine scheduler
Marble diagram generator (.Net 4)
Shameless plug: http://bit.ly/rxrus