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 ID: 380528
Download Presentation The PPT/PDF document "An Introduction to the" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
An Introduction to theReactive Extensions
Ivan
Towlson
MindscapeSlide2
Composable operators for working with sets of data
Reintroducing LINQSlide3
IEnumerable:the little interface that couldSlide4
Extends IEnumerable to support translation of LINQ queries for processing by another engine
IQueryable
:
the little interface that takes twelve years to implementSlide5
IEnumerable is a pull model
Unpredictable streams are better handled by a
push
model
Pulling and pushingSlide6
Introducing
IObservableSlide7
interface
IEnumerable
<T> {
IEnumerator
<T>
GetEnumerator
();
}
interface
IObservable
<T> {
IDisposable
Subscribe(
IObserver
<T>);
}Slide8
interface
IEnumerator
<T> {
bool
MoveNext
();
T Current;
}
interface
IObservable
<T> {
void
OnNext
(T);
void
OnError
(Exception);
void
OnCompleted
();
}Slide9
An implementation of the LINQ standard query operators (and more) for the IObservable interface
Introducing the
Reactive ExtensionsSlide10
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?Slide11
A unified, declarative, composable way of working with asynchronous sources
Builds on existing sources of asynchrony, rather than replacing them
Introducing the
Reactive ExtensionsSlide12
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 ExtensionsSlide13
Where does asynchronous data come from?Slide14
Events as asynchronous dataSlide15
Revisiting the asynchronous method pair patternSlide16
Not useful in themselves, but useful for compositionObservable.Create: explicitly spelling out the event sequence (like an iterator)
Primitive constructors and generatorsSlide17
The pulls push
and the pushers pull
with apologies to P J HarveySlide18
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
AsXxxSlide19
What can we do with asynchronous data
once we’ve got a source?Slide20
WhereSelect / SelectMany
Count / Any / All
and all the rest
LINQ operatorsSlide21
ScanBuffer (with time and count options)TakeUntil
Merge /
Amb
And a whole lot more besidesSlide22
SampleThrottle / TimeoutTimestamp /
TimeInterval
DistinctUntilChanged
And a whole lot more besidesSlide23
What about timing?
What about threading?Slide24
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?
ISchedulerSlide25
ImmediateThread pool, task poolWPF or
WinForms
UI thread
Custom
SchedulersSlide26
ObserveOnSubscribeOn
Or we could just do it
right here on the UI threadSlide27
Sorry, Visual Basic fans, butthe doors are now locked
A brief interlude for the
obligatory
eggheadtudeSlide28
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
homoiconicSlide29
Orthogonality
fail?Slide30
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 MESlide31
Also known as IQueryableObservable or
IShouldntChooseNamesWhileStoned
Introducing
IQbservableSlide32
Allows queries to be translated for processing by external push sources
Like
IQueryable
, filtering, aggregation, etc. can be performed at the source
Introducing
IQbservableSlide33
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 WMISlide34
.NET, Silverlight: download from MSDNWindows Phone 7: included in ROM but can download updated version
JavaScript: download from MSDN
AvailabilitySlide35
MSDN DevLabs – Projects > Rx
PDC talk – FT10, Bart de
Smet
http://blogs.msdn.com/b/rxteam/
Rx Design Guidelines document
ResourcesSlide36
Thanks!
Ivan
Towlson
ivan@mindscape.co.nz | ivan@hestia.cc
http://hestia.typepad.com/flatlander/