360 likes | 727 Views
An Introduction to the Reactive Extensions. Ivan Towlson Mindscape. Reintroducing LINQ. Composable operators for working with sets of data. IEnumerable : the little interface that could. IQueryable : the little interface that takes twelve years to implement.
E N D
An Introduction to theReactive Extensions Ivan Towlson Mindscape
Reintroducing LINQ Composable operators for working with sets of data
IQueryable:the little interface that takes twelve years to implement Extends IEnumerable to support translation of LINQ queries for processing by another engine
Pulling and pushing IEnumerable is a pull model Unpredictable streams are better handled by a push model
interface IEnumerable<T> { IEnumerator<T> GetEnumerator(); } interface IObservable<T> { IDisposable Subscribe(IObserver<T>); }
interface IEnumerator<T> { bool MoveNext(); T Current;} interface IObservable<T> { void OnNext(T); void OnError(Exception); void OnCompleted(); }
Introducing theReactive Extensions An implementation of the LINQ standard query operators (and more) for the IObservable interface
How? Translatable (expression trees) IQueryable e.g LINQ to SQL IEnumerable LINQ to Objects IObservable “LINQ to Events” Fixed (MSIL) What? Pull (interactive) Push (reactive)
Introducing theReactive Extensions A unified, declarative, composable way of working with asynchronous sources Builds on existing sources of asynchrony, rather than replacing them
Introducing theReactive 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
Primitive constructors and generators Not useful in themselves, but useful for composition Observable.Create: explicitly spelling out the event sequence (like an iterator)
The pulls pushand the pushers pull with apologies to P J Harvey
How? Translatable (expression trees) IQueryable e.g LINQ to SQL AsXxx IEnumerable LINQ to Objects IObservable “LINQ to Events” Fixed (MSIL) ToXxx What? Pull (interactive) Push (reactive)
What can we do with asynchronous data once we’ve got a source?
LINQ operators Where Select / SelectMany Count / Any / All and all the rest
And a whole lot more besides Scan Buffer (with time and count options) TakeUntil Merge / Amb
And a whole lot more besides Sample Throttle / Timeout Timestamp / TimeInterval DistinctUntilChanged
How? Translatable (expression trees) IQueryable e.g LINQ to SQL IEnumerable LINQ to Objects IObservable “LINQ to Events” Fixed (MSIL) What? Pull (interactive) Push (reactive) When? IScheduler
Schedulers Immediate Thread pool, task pool WPF or WinForms UI thread Custom
Or we could just do itright here on the UI thread ObserveOn SubscribeOn
A brief interlude for theobligatory eggheadtude Sorry, Visual Basic fans, butthe doors are now locked
How? Translatable (expression trees) IQueryable e.g LINQ to SQL homoiconic IEnumerable LINQ to Objects IObservable “LINQ to Events” Fixed (MSIL) What? Pull (interactive) Push (reactive) dual
How? FILL ME Translatable (expression trees) IQueryable e.g LINQ to SQL IEnumerable LINQ to Objects IObservable “LINQ to Events” Fixed (MSIL) What? Pull (interactive) Push (reactive)
Introducing IQbservable 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
How? LINQ to * Translatable (expression trees) IQueryable e.g LINQ to SQL IQbservable e.g. LINQ to WMI IEnumerable LINQ to Objects IObservable “LINQ to Events” Fixed (MSIL) What? Pull (interactive) Push (reactive)
Availability .NET, Silverlight: download from MSDN Windows Phone 7: included in ROM but can download updated version JavaScript: download from MSDN
Resources MSDN DevLabs– Projects > Rx PDC talk – FT10, Bart de Smet http://blogs.msdn.com/b/rxteam/ Rx Design Guidelines document
Thanks! Ivan Towlson ivan@mindscape.co.nz | ivan@hestia.cc http://hestia.typepad.com/flatlander/