Reactive Extensions
for .NET
Andrei Marukovich
contact@lunarfrog.com
twitter: @amarukovich
Rx is a library for composing
asynchronous and event-based
programs using observable sequences
and LINQ-style query operat...
Observables
• IObservable<T>
• IObserver<T>
Enumerables
interface IEnumerable<out T>
{
IEnumerator<T> GetEnumerator();
}
interface IEnumerator<out T> : IDisposable
{
...
Pull and Push
Consumer
Pull
Any new data?

IEnumerable

•
•
•
•

Sensors
UI events
Web services
Social media

Source

IObs...
Observables
interface IObservable<out T>
{
IDisposable Subscribe(IObserver<T> observer);
}
interface IObserver<out T>
{
vo...
Using observables
IObservable

IObserver

Subscribe

OnNext

OnNext

OnComplete
Contract
OnNext* [OnComplete | OnError]
1

2

1

3
2

1

2

1

2 3

4

3

3

4
4

5

6
Demo: Observable sequences
• Subject<T>
• Observable
• Never, Empty, Return, Throw, Create
• Range, Generate, Repeat
• Int...
LINQ
Filtering
• Where, Distinct, Skip(While|Last|Until), Take

Inspection
• Any, All

Aggregation and transformation
• Co...
Demo: LINQ
• Common LINQ operators
• Combining sequences
• Pairing
• Sequentially
• Concurrently
Rx bridges
• Observable.FromAsync()
• Observable.FromEvent()
• Observable.FromEventPattern()
Demo: LINQ to events
• Time shifting
• Throttle
• Sample
• Buffer
• Delay
Concurrency
SubscribeOn
• Invocation of the subscription

ObserveOn
• Observing of notifications
Demo: Concurrency
• Schedulers
Schedulers
• ImmediateScheduler

• CurrentThreadScheduler
• DispatcherScheduler
• EventLoopScheduler
• NewThreadScheduler
...
Flavors of Rx
.NET
• WinForms, WPF, Silverlight
• Windows Phone, WinRT
• ASP
.NET

Beyond .NET
• RxJS, RxCpp
• RxPy, Rx.rb
Resources
• http://rx.codeplex.com/
• http://bit.ly/Rx-Home
Thank you!

Andrei Marukovich
contact@lunarfrog.com
twitter: @amarukovich
Upcoming SlideShare
Loading in …5
×

Reactive Extensions for .NET

1,377 views

Published on

Published in: Spiritual, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,377
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
17
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Reactive Extensions for .NET

  1. 1. Reactive Extensions for .NET Andrei Marukovich contact@lunarfrog.com twitter: @amarukovich
  2. 2. Rx is a library for composing asynchronous and event-based programs using observable sequences and LINQ-style query operators. Rx = Observables + LINQ + Schedulers
  3. 3. Observables • IObservable<T> • IObserver<T>
  4. 4. Enumerables interface IEnumerable<out T> { IEnumerator<T> GetEnumerator(); } interface IEnumerator<out T> : IDisposable { T Current { get; } bool MoveNext(); void Reset(); }
  5. 5. Pull and Push Consumer Pull Any new data? IEnumerable • • • • Sensors UI events Web services Social media Source IObservable Push New data available!
  6. 6. Observables interface IObservable<out T> { IDisposable Subscribe(IObserver<T> observer); } interface IObserver<out T> { void OnNext(T value); void OnError(Exception error); void OnCompleted(); }
  7. 7. Using observables IObservable IObserver Subscribe OnNext OnNext OnComplete
  8. 8. Contract OnNext* [OnComplete | OnError] 1 2 1 3 2 1 2 1 2 3 4 3 3 4 4 5 6
  9. 9. Demo: Observable sequences • Subject<T> • Observable • Never, Empty, Return, Throw, Create • Range, Generate, Repeat • Interval, Timer
  10. 10. LINQ Filtering • Where, Distinct, Skip(While|Last|Until), Take Inspection • Any, All Aggregation and transformation • Count, Min, Max, Average, Select
  11. 11. Demo: LINQ • Common LINQ operators • Combining sequences • Pairing • Sequentially • Concurrently
  12. 12. Rx bridges • Observable.FromAsync() • Observable.FromEvent() • Observable.FromEventPattern()
  13. 13. Demo: LINQ to events • Time shifting • Throttle • Sample • Buffer • Delay
  14. 14. Concurrency SubscribeOn • Invocation of the subscription ObserveOn • Observing of notifications
  15. 15. Demo: Concurrency • Schedulers
  16. 16. Schedulers • ImmediateScheduler • CurrentThreadScheduler • DispatcherScheduler • EventLoopScheduler • NewThreadScheduler • Thread/Task Pool • TestScheduler
  17. 17. Flavors of Rx .NET • WinForms, WPF, Silverlight • Windows Phone, WinRT • ASP .NET Beyond .NET • RxJS, RxCpp • RxPy, Rx.rb
  18. 18. Resources • http://rx.codeplex.com/ • http://bit.ly/Rx-Home
  19. 19. Thank you! Andrei Marukovich contact@lunarfrog.com twitter: @amarukovich

×