An Introduction to the Reactive Extensions Ivan Towlson Mindscape
Composable operators for working with sets of data Reintroducing LINQ
IEnumerable: the little interface that could
Extends IEnumerable to support translation of LINQ queries for processing by another engine IQueryable: the little interface that takes twelve years to implement
IEnumerable is a pull model Unpredictable streams are better handled by a push model Pulling and pushing
Introducing IObservable
interface IEnumerable { IEnumerator GetEnumerator(); } interface IObservable { IDisposable Subscribe(IObserver ); }
interface IEnumerator { bool MoveNext(); T Current; } interface IObservable { void OnNext(T); void OnError(Exception); void OnCompleted(); }
An implementation of the LINQ standard query operators (and more) for the IObservable interface Introducing the Reactive Extensions
IEnumerable LINQ to Objects IObservable “LINQ to Events” IQueryable e.g LINQ to SQL Pull (interactive) Push (reactive) Translatable (expression trees) Fixed (MSIL) How? What?
A unified, declarative, composable way of working with asynchronous sources Builds on existing sources of asynchrony, rather than replacing them Introducing the Reactive Extensions
Like LINQ, Rx doesn’t do anything you couldn’t do in your own code, but it wraps up a lot of boilerplate and ad hoc code into convenient, composable operators Introducing the Reactive Extensions
Where does asynchronous data come from?
Events as asynchronous data
Revisiting the asynchronous method pair pattern
Not useful in themselves, but useful for composition Observable.Create: explicitly spelling out the event sequence (like an iterator) Primitive constructors and generators
The pulls push and the pushers pull with apologies to P J Harvey
IEnumerable LINQ to Objects IObservable “LINQ to Events” IQueryable e.g LINQ to SQL Pull (interactive) Push (reactive) Translatable (expression trees) Fixed (MSIL) How? What? ToXxx AsXxx
What can we do with asynchronous data once we’ve got a source?
Where Select / SelectMany Count / Any / All and all the rest LINQ operators
Scan Buffer (with time and count options) TakeUntil Merge / Amb And a whole lot more besides
Sample Throttle / Timeout Timestamp / TimeInterval DistinctUntilChanged And a whole lot more besides
What about timing? What about threading?
IEnumerable LINQ to Objects IObservable “LINQ to Events” IQueryable e.g LINQ to SQL Pull (interactive) Push (reactive) Translatable (expression trees) Fixed (MSIL) How? What? When? IScheduler
Immediate Thread pool, task pool WPF or WinForms UI thread Custom Schedulers
ObserveOn SubscribeOn Or we could just do it right here on the UI thread
Sorry, Visual Basic fans, but the doors are now locked A brief interlude for the obligatory eggheadtude
IEnumerable LINQ to Objects IObservable “LINQ to Events” IQueryable e.g LINQ to SQL Pull (interactive) Push (reactive) Translatable (expression trees) Fixed (MSIL) How? What? dual homoiconic
Orthogonality fail?
IEnumerable LINQ to Objects IObservable “LINQ to Events” IQueryable e.g LINQ to SQL Pull (interactive) Push (reactive) Translatable (expression trees) Fixed (MSIL) How? What? FILL ME
Also known as IQueryableObservable or IShouldntChooseNamesWhileStoned Introducing IQbservable
Allows queries to be translated for processing by external push sources Like IQueryable, filtering, aggregation, etc. can be performed at the source Introducing IQbservable
LINQ to * IEnumerable LINQ to Objects IObservable “LINQ to Events” IQueryable e.g LINQ to SQL Pull (interactive) Push (reactive) Translatable (expression trees) Fixed (MSIL) How? What? IQbservable e.g. LINQ to WMI
.NET, Silverlight: download from MSDN Windows Phone 7: included in ROM but can download updated version JavaScript: download from MSDN Availability
MSDN DevLabs – Projects > Rx PDC talk – FT10, Bart de Smet Rx Design Guidelines document Resources
Thanks! Ivan Towlson |