Your SlideShare is downloading. ×
0
Real-world applications of
Reactive Extensions for .NET (Rx)
Jonas Chapuis, Ph.D., Nexthink S.A.
About me
jonas.chapuis@nexthink.com
www.nexthink.com/careers
“Functional programming allows developers to
describe what they want to do, rather than forcing
them to describe how they ...
Exercise

readable
compact
safe
JAY
JANE
MARRY
HARRY

Versus:
IEnumerable & IEnumerator
Oh my…

TimeoutException!
Ok, how about this:

nice
IObservable & IObserver
Yin & Yang
Pull collections

Push collections

MoveNext()

•
•
•
•
•

In memory collections
Database queries
Generated seq...
Where does Rx fit?

Rx shines for
– Declarative syntax & compositionality
– Easy time handling (timeout, throttling, etc.)...
Example: search box
• Demo
Search pipeline
react

reactive

input
search
SelectMany

search
Input pipeline
r
input
Throttle 200ms

Where length > 2

DistinctUntilChanged

re

rea

reac

reaci

reac

reactive
Race condition
react

reactive

input
search

search

SelectMany
TakeUntil
react

reactive

input
search
TakeUntil(input)
search
TakeUntil(input)

SelectMany
Timeout
react
input
search
Timeout

SelectMany
Search example Rx network
Property
changed
events

react
reactive
...

Timer

throttle
distinct
search

DictService
Task<T...
Example: stock quotes stream
• Demo
Buffer(5)
MSFT
27.56

MSFT
26.4

MSFT
28.1

MSFT
{27.56, 26.4, 28.1, 30.2, 25.6}

MSFT
30.2

MSFT
25.6

MSFT
29.2

MSFT
32...
Buffer(5,1)
MSFT
27.56

MSFT
26.4

MSFT
28.1

MSFT
30.2

MSFT
25.6

MSFT
29.2

MSFT
32.1
Example: buffer in time
• Demo
Interoperability with the TPL
• ToObservable()

• ToTask()
Example: asynchronous spellchecker
Demo
Rx on other platforms
• RxJs
– Autocomplete, drag&drop, animation, etc.

• RxJava
– Used for server-side concurrency (heav...
Links
•
•
•
•

http://www.introtorx.com/
http://blogs.msdn.com/b/rxteam/
Beginner's Guide to the Reactive Extensions
http:...
“GitHub for Windows uses the Reactive Extensions for almost everything
it does, including network requests, UI events, man...
Upcoming SlideShare
Loading in...5
×

Real-world applications of the Reactive Extensions

1,903

Published on

Some concrete exemples of using the Reactive Extensions (Rx) for app development

Published in: Technology, Sports

Transcript of "Real-world applications of the Reactive Extensions"

  1. 1. Real-world applications of Reactive Extensions for .NET (Rx) Jonas Chapuis, Ph.D., Nexthink S.A.
  2. 2. About me jonas.chapuis@nexthink.com www.nexthink.com/careers
  3. 3. “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
  4. 4. Exercise readable compact safe JAY JANE MARRY HARRY Versus:
  5. 5. IEnumerable & IEnumerator
  6. 6. Oh my… TimeoutException!
  7. 7. Ok, how about this: nice
  8. 8. IObservable & IObserver
  9. 9. Yin & Yang Pull collections Push collections MoveNext() • • • • • In memory collections Database queries Generated sequences Message queues … Rx • • • • • OnNext() Event streams Asynchronous computations Asynchronous queries Asynchronous enumerations …
  10. 10. Where does Rx fit? Rx shines for – Declarative syntax & compositionality – Easy time handling (timeout, throttling, etc.) – Error handling – Cancellation – Testing
  11. 11. Example: search box • Demo
  12. 12. Search pipeline react reactive input search SelectMany search
  13. 13. Input pipeline r input Throttle 200ms Where length > 2 DistinctUntilChanged re rea reac reaci reac reactive
  14. 14. Race condition react reactive input search search SelectMany
  15. 15. TakeUntil react reactive input search TakeUntil(input) search TakeUntil(input) SelectMany
  16. 16. Timeout react input search Timeout SelectMany
  17. 17. Search example Rx network Property changed events react reactive ... Timer throttle distinct search DictService Task<T> takeuntil selectmany timeout OnNext Observer Timer OnError OnError & OnComplete are terminating, i.e. trigger disposal of the network
  18. 18. Example: stock quotes stream • Demo
  19. 19. Buffer(5) MSFT 27.56 MSFT 26.4 MSFT 28.1 MSFT {27.56, 26.4, 28.1, 30.2, 25.6} MSFT 30.2 MSFT 25.6 MSFT 29.2 MSFT 32.1
  20. 20. Buffer(5,1) MSFT 27.56 MSFT 26.4 MSFT 28.1 MSFT 30.2 MSFT 25.6 MSFT 29.2 MSFT 32.1
  21. 21. Example: buffer in time • Demo
  22. 22. Interoperability with the TPL • ToObservable() • ToTask()
  23. 23. Example: asynchronous spellchecker Demo
  24. 24. 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
  25. 25. Links • • • • http://www.introtorx.com/ http://blogs.msdn.com/b/rxteam/ Beginner's Guide to the Reactive Extensions http://www.reactivemanifesto.org/
  26. 26. “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
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×