real-world applications of the reactive extensions
DESCRIPTION
Some concrete exemples of using the Reactive Extensions (Rx) for app developmentTRANSCRIPT
![Page 1: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/1.jpg)
Real-world applications of Reactive Extensions for .NET (Rx)
Jonas Chapuis, Ph.D., Nexthink S.A.
![Page 3: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/3.jpg)
“Functional programming allows developers to describe what they want to do, rather than forcing them to describe how they want to do it.”
Anders Hejlsberg, C# creator
![Page 4: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/4.jpg)
Exercise
Versus:JAY
JANE
MARRY
HARRY
readablecompactsafe
![Page 5: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/5.jpg)
IEnumerable & IEnumerator
![Page 6: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/6.jpg)
Oh my…
TimeoutException!
![Page 7: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/7.jpg)
Ok, how about this:
nice
![Page 8: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/8.jpg)
IObservable & IObserver
![Page 9: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/9.jpg)
Yin & Yang
Pull collections Push collections
MoveNext() OnNext()Rx
• Event streams• Asynchronous computations• Asynchronous queries• Asynchronous enumerations• …
• In memory collections• Database queries• Generated sequences• Message queues• …
![Page 10: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/10.jpg)
Where does Rx fit?
Rx shines for– Declarative syntax & compositionality
– Easy time handling (timeout, throttling, etc.)
– Error handling
– Cancellation
– Testing
![Page 11: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/11.jpg)
Example: search box
• Demo
![Page 12: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/12.jpg)
search
Search pipeline
input
react
search
reactive
SelectMany
![Page 13: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/13.jpg)
Input pipeline
input
r re rea reac reaci reac reactive
Throttle 200ms
Where length > 2
DistinctUntilChanged
![Page 14: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/14.jpg)
search
search
Race condition
input
react reactive
SelectMany
![Page 15: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/15.jpg)
TakeUntil
input
react reactive
SelectMany
search
TakeUntil(input)
search
TakeUntil(input)
![Page 16: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/16.jpg)
Timeout
input
react
SelectMany
search
Timeout
![Page 17: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/17.jpg)
Search example Rx network
throttle
timeout
distinct
selectmany
search
takeuntil
Observer
react
reactive
...
Property changed events
Timer
Timer
DictServiceTask<T>
OnError & OnComplete are terminating, i.e. trigger disposal of the network
OnError
OnNext
![Page 18: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/18.jpg)
Example: stock quotes stream
• Demo
![Page 19: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/19.jpg)
Buffer(5)
MSFT27.56
MSFT26.4
MSFT28.1
MSFT30.2
MSFT25.6
MSFT29.2
MSFT32.1
MSFT{27.56, 26.4, 28.1, 30.2, 25.6}
![Page 20: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/20.jpg)
Buffer(5,1)
MSFT27.56
MSFT26.4
MSFT28.1
MSFT30.2
MSFT25.6
MSFT29.2
MSFT32.1
![Page 21: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/21.jpg)
Example: buffer in time
• Demo
![Page 22: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/22.jpg)
Interoperability with the TPL
• ToObservable()
• ToTask()
![Page 23: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/23.jpg)
Example: asynchronous spellchecker
Demo
![Page 24: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/24.jpg)
Rx on other platforms
• RxJs– Autocomplete, drag&drop, animation, etc.
• RxJava– Used for server-side concurrency (heavy requests
instead of multiple light requests)– “functional reactive is superior to futures and
callbacks”– using IObservable<T> allows choosing asynchronous
or synchronous execution & I/O at runtime
• RxRb• RxPy
![Page 25: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/25.jpg)
Links
• http://www.introtorx.com/
• http://blogs.msdn.com/b/rxteam/
• Beginner's Guide to the Reactive Extensions
• http://www.reactivemanifesto.org/
![Page 26: Real-world applications of the Reactive Extensions](https://reader034.vdocuments.net/reader034/viewer/2022052321/554ebe1ab4c905de468b494d/html5/thumbnails/26.jpg)
“GitHub for Windows uses the Reactive Extensions for almost everything it does, including network requests, UI events, managing child processes […] while still having 100% deterministic, reliable unit tests. The desktop developers at GitHub loved Rx so much, that the Mac team created their own version of Rx and ReactiveUI, called ReactiveCocoa, and are now using it on the Mac to obtain similar benefits.”
Paul Betts, GitHub