SlideShare a Scribd company logo
1
Tamir Dresher
Senior Software Architect
J
Reactive Extensions 101
222
• Software architect, consultant and instructor
• Software Engineering Lecturer @ Ruppin Academic Center
• Reactive Extensions in .NET (Manning)
@tamir_dresher
tamirdr@codevalue.net
http://www.TamirDresher.com.
About Me
Reactive Extensions
Your headache relief pill to Asynchronous Event
based applications
Async
Push
Triggers
Events
Reacting to changes
4
Social
media
IoT
GPS
External Services
Your System
So Many Sources…So Many Sources…
Agenda
Rx building blocks – Observable and Observers
Creating Observables
Rx queries with Rx operators
Managing Concurrency with Rx Schedulers
6
Source/
Producer
Target/
Consumer
Producer-ConsumerProducer-Consumer
Source/
Producer
Target/
Consumer
Source/
Producer
Source/
Producer
Target/
Consumer
Target/
Consumer
Producer-ConsumerProducers-Consumers
IEnumerable<Message> LoadMessages(string hashtag)
{
var statuses = facebook.Search(hashtag);
var tweets = twitter.Search(hashtag);
var updates = linkedin.Search(hashtag);
return statuses.Concat(tweets).Concat(updates);
}
Twitter App
Linkedin
Facebook
Pull ModelPull Model
???? LoadMessages(string hashtag)
{
facebook.Search(hashtag);
twitter.Search(hashtag);
linkedin.Search(hashtag);
}
DoSomething( )msg
Push ModelPush Model
Push model with Events
11
var mgr = new SocialNetworksManager();
mgr.MessageAvailable += (sender, msg) => {//do something};
mgr.LoadMessages("Rx");
class SocialNetworksManager
{
//members
public event EventHandler<Message> MessageAvailable;
public void LoadMessages(string hashtag)
{
var statuses = _facebook.Search(hashtag);
NotifyMessages(statuses);
:
}
}
hard to unsubscribe non-composable
can’t send as argument
no isolation
???? LoadMessages(string hashtag)
{
facebook.Search(hashtag);
twitter.Search(hashtag);
linkedin.Search(hashtag);
}
DoSomething( )msg
Push ModelPush Model
observable observer
Subscribe(observer)
subscription
OnNext(X1)
OnNext(Xn)
⁞
⁞
IDisposable
Observables and ObserversObservables and Observers
OnCompleted()
OnError(Exception)

observable observer
⁞
Observables and ObserversObservables and Observers
namespace System
{
public interface IObservable<out T>
{
IDisposable Subscribe(IObserver<T> observer);
}
public interface IObserver<in T>
{
void OnNext(T value);
void OnError(Exception error);
void OnCompleted();
}
}
InterfacesInterfaces
Rx packages
16
Push ModelPush Model with Rx Observables
class ReactiveSocialNetworksManager
{
//members
public IObservable<Message> ObserveMessages(string hashtag)
{
:
}
}
var mgr = new ReactiveSocialNetworksManager();
mgr.ObserveLoadedMessages("Rx")
.Subscribe(
msg => Console.WriteLine($"Observed:{msg} t"),
ex => { /*OnError*/ },
() => { /*OnCompleted*/ });
Creating Observables
IObservable<Message> ObserveMessages(string hashtag)
{
}
return Observable.Create( async (o) =>
{
});
var messages = await GetMessagesAsync(hashtag);
foreach(var m in messages)
{
o.OnNext(m);
}
o.OnCompleted();
Pull To PushPull To Push
Subscribe function
FacebookClient:
IObservable<Message> ObserveMessages(string hashtag)
{
}
var messages = await GetMessagesAsync(hashtag);
return messages.ToObservable();
Built-in ConvertersBuilt-in Converters
Note: All observers will get the
same emitted messages
IObservable<Message> ObserveMessages(string hashtag)
{
}
return Observable.Defer( async () =>
{
});
var messages = await GetMessagesAsync(hashtag);
return messages.ToObservable();
Built-in ConvertersDefering the observable creation
Note: Every observer will get the
“fresh” emitted messages
Observable.Merge(
facebook.ObserveMessages(hashtag),
twitter.ObserveMessages(hashtag),
linkedin.ObserveMessages(hashtag)
);
Built-in OperatorsBuilt-in Combinators (combining operators)
Observable.Range(1, 10)
.Subscribe(x => Console.WriteLine(x));
Observable.Interval(TimeSpan.FromSeconds(1))
.Subscribe(x => Console.WriteLine(x));
Observable.FromEventPattern(SearchBox, "TextChanged")
⁞
⁞
1 sec 1 sec
Observables Factories
⁞
Observables Factories
Observable Queries (Rx Operators)
Filtering Projection Partitioning Joins Grouping Set
Element Generation Quantifiers Aggregation Error HandlingTime and
Concurrency
Where
OfType
Select
SelectMany
Materialize
Skip
Take
TakeUntil
CombineLatest
Concat
join
GroupBy
GroupByUntil
Buffer
Distinct
DistinctUntilChanged
Timeout
TimeInterval
ElementAt
First
Single
Range
Repeat
Defer
All
Any
Contains
Sum
Average
Scan
Catch
OnErrorResumeNext
Using
Rx operators
Operator2 Creates an IObservable<T3>
IObservable parameters
Operator
1
Subscribe( )
observer
observable
… Operator
N
Operator1
Creates an IObservable<T2>
IObservable<T>
Original source
observer
Subscribe
ComposabilityComposability
g(x)
f(x)
Observable Query PipelineObservable Query Pipeline
Reactive SearchReactive Search
1. At least 3 characters
2. Don’t overflow server (0.5 sec delay)
3. Don’t send the same string again
4. Discard results if another search was requested
Reactive Search - RulesReactive Search - Rules
Rx 101  - Tamir Dresher - Copenhagen .NET User Group
31
32
Where(s => s.Length > 2 )
 
33
Where(s => s.Length > 2 )
 
Throttle(TimeSpan.FromSeconds(0.5))
34
Where(s => s.Length > 2 )
 
Throttle(TimeSpan.FromSeconds(0.5))
DistinctUntilChanged()

36
Select(text => SearchAsync(text))
“REA”
“REAC”
Switch()
“REA” results are ignored since we
switched to the “REAC” results
Var textChanged =
Observable.FromEventPattern(txt, “TextChanged”)
.Select(_=>txt.Text);
textChanged
.Where(text=>text.Length>3)
.Throttle(TimeSpan.FromSeconds(0.5))
.DistinctUntilChanged()
.SelectMany(text => SearchAsync(text))
.Switch()
.Subscribe(/*handle the results*/);
var $input = $('#input'),
$results = $('#results');
Rx.Observable.fromEvent($input, 'keyup')
.map(e => e.target.value)
.filter(text => text.length > 3)
.throttle(500 /* ms */)
.distinctUntilChanged()
.flatMapLatest(searchWikipedia)
.subscribe(data => {
var res = data[1];
$results.empty();
$.each(res, (_, value) => $('<li>' + value + '</li>').appendTo($results));
}, error => {
/* handle any errors */
$results.empty();
$('<li>Error: ' + error + '</li>').appendTo($results);
});
Abstracting Time and Concurrency
What will be the output?
The Repeat operator resubscribes the observer when the observable completes
Most developers falsely believe that the program will immediately dispose the subscription and
nothing will be written to the console
Rx is not concurrent unless it explicitly told to
The example above writes the sequence 1-5 indefinitely to the console
40
var subscription =
Observable.Range(1, 5)
.Repeat()
.Subscribe(x => Console.WriteLine(x));
subscription.Dispose();
Thread Pool
Task Scheduler
other
SchedulersSchedulers
public interface IScheduler
{
DateTimeOffset Now { get; }
IDisposable Schedule<TState>( TState state,
Func<IScheduler, TState, IDisposable> action);
IDisposable Schedule<TState>(TimeSpan dueTime,
TState state,
Func<IScheduler, TState, IDisposable> action);
IDisposable Schedule<TState>(DateTimeOffset dueTime,
TState state,
Func<IScheduler, TState, IDisposable> action);
}
//
// Runs a timer on the default scheduler
//
IObservable TimeSpan
//
// Every operator that introduces concurrency
// has an overload with an IScheduler
//
IObservable T TimeSpan
IScheduler scheduler);
Parameterizing ConcurrencyParameterizing Concurrency
textChanged
.Throttle(TimeSpan.FromSeconds(0.5),
DefaultScheduler.Instance)
.DistinctUntilChanged()
.SelectMany(text => SearchAsync(text))
.Switch()
.Subscribe(/*handle the results*/);
//
// runs the observer callbacks on the specified
// scheduler.
//
IObservable T ObserveOn<T>(IScheduler);
//
// runs the observer subscription and unsubsciption on
// the specified scheduler.
//
IObservable T SubscribeOn<T>(IScheduler)
Changing Execution ContextChanging Execution Context
textChanged
.Throttle(TimeSpan.FromSeconds(0.5))
.DistinctUntilChanged()
.Select(text => SearchAsync(text))
.Switch()
.ObserveOn(DispatcherScheduler.Current)
.Subscribe(/*handle the results*/);
Changing Execution ContextChanging Execution Context
textChanged
.Throttle(TimeSpan.FromSeconds(0.5))
.DistinctUntilChanged()
.Select(text => SearchAsync(text))
.Switch()
.ObserveOnDispatcher()
.Subscribe(/*handle the results*/);
Changing Execution ContextChanging Execution Context
Your headache relief pill to Asynchronous and
Event based applications
Async
Push
Triggers
Events
Reactive ExtensionsReactive Extensions
www.manning.com/dresher www.reactivex.io github.com/Reactive-Extensions
Discount code:
dreshermu
Thank You
What will the following Console app print out?
51
http://landing.oz-code.com/CPH

More Related Content

PPTX
Rx for Android & iOS by Harin Trivedi
PPTX
Rxandroid
PDF
Tricentis Tosca - Email Notification of Execution Reports
PDF
Testing with Containers
PDF
Programming Sideways: Asynchronous Techniques for Android
PDF
Long-Awaited Check of CryEngine V
PPTX
Reactive Programming no Android
PPTX
Reactive Programming on Android
Rx for Android & iOS by Harin Trivedi
Rxandroid
Tricentis Tosca - Email Notification of Execution Reports
Testing with Containers
Programming Sideways: Asynchronous Techniques for Android
Long-Awaited Check of CryEngine V
Reactive Programming no Android
Reactive Programming on Android

What's hot (12)

TXT
Lucene application
PPTX
RxJava 2 Reactive extensions for the JVM
PPTX
Testing time and concurrency Rx
PDF
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
PDF
Jenkins log monitoring with elk stack
DOCX
Button tambah
PPTX
Splunk HTTP Event Collector
PDF
Ardunio + MySQL = direct database connections.
PDF
Next generation message driven systems with Akka
PDF
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
DOCX
Assignment 2
PDF
(2) c sharp introduction_basics_part_i
Lucene application
RxJava 2 Reactive extensions for the JVM
Testing time and concurrency Rx
Hacking the Mesh: Extending Istio with WebAssembly Modules | DevNation Tech Talk
Jenkins log monitoring with elk stack
Button tambah
Splunk HTTP Event Collector
Ardunio + MySQL = direct database connections.
Next generation message driven systems with Akka
Jupyter Notebooks for machine learning on Kubernetes & OpenShift | DevNation ...
Assignment 2
(2) c sharp introduction_basics_part_i
Ad

Viewers also liked (11)

PPTX
Rx 101 Codemotion Milan 2015 - Tamir Dresher
PPTX
Science and software development
PPTX
Building responsive applications with Rx - CodeMash2017 - Tamir Dresher
PDF
Streaming ETL With Akka.NET
PPTX
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
PPTX
Reactive Development: Commands, Actors and Events. Oh My!!
PDF
Distributed Transactions in Akka.NET
PPT
An introduction to maven gradle and sbt
PPTX
CQRS Evolved - CQRS + Akka.NET
PPTX
.NET Debugging tricks you wish you knew tamir dresher
PPTX
Building responsive application with Rx - confoo - tamir dresher
Rx 101 Codemotion Milan 2015 - Tamir Dresher
Science and software development
Building responsive applications with Rx - CodeMash2017 - Tamir Dresher
Streaming ETL With Akka.NET
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
Reactive Development: Commands, Actors and Events. Oh My!!
Distributed Transactions in Akka.NET
An introduction to maven gradle and sbt
CQRS Evolved - CQRS + Akka.NET
.NET Debugging tricks you wish you knew tamir dresher
Building responsive application with Rx - confoo - tamir dresher
Ad

Similar to Rx 101 - Tamir Dresher - Copenhagen .NET User Group (20)

PPTX
Reactive Extensions: classic Observer in .NET
PDF
Buy ebook Rx.NET in Action with Examples in C# 1st Edition Tamir Dresher chea...
PPTX
Tamir Dresher - Reactive Extensions (Rx) 101
PPTX
Taming Asynchrony using RxJS
PDF
Full Download Rx.NET in Action with Examples in C# 1st Edition Tamir Dresher ...
PDF
Reactive Extensions
PPTX
Understanding reactive programming with microsoft reactive extensions
PPTX
Functional reactive programming
PPTX
Rx- Reactive Extensions for .NET
PDF
RxJS - The Reactive extensions for JavaScript
PPTX
PPTX
RxJS and Reactive Programming - Modern Web UI - May 2015
PPTX
Rx – reactive extensions
PPTX
Samuele Resca - REACTIVE PROGRAMMING, DAMN. IT IS NOT ABOUT REACTJS - Codemot...
PPTX
RxJS In-Depth - AngularConnect 2015
PPTX
Reactive Extensions
PPTX
Introduction to Reactive Extensions (Rx)
PDF
Reactive Xamarin. UA Mobile 2016.
PDF
RxJava@Android
PPTX
Rxjs marble-testing
Reactive Extensions: classic Observer in .NET
Buy ebook Rx.NET in Action with Examples in C# 1st Edition Tamir Dresher chea...
Tamir Dresher - Reactive Extensions (Rx) 101
Taming Asynchrony using RxJS
Full Download Rx.NET in Action with Examples in C# 1st Edition Tamir Dresher ...
Reactive Extensions
Understanding reactive programming with microsoft reactive extensions
Functional reactive programming
Rx- Reactive Extensions for .NET
RxJS - The Reactive extensions for JavaScript
RxJS and Reactive Programming - Modern Web UI - May 2015
Rx – reactive extensions
Samuele Resca - REACTIVE PROGRAMMING, DAMN. IT IS NOT ABOUT REACTJS - Codemot...
RxJS In-Depth - AngularConnect 2015
Reactive Extensions
Introduction to Reactive Extensions (Rx)
Reactive Xamarin. UA Mobile 2016.
RxJava@Android
Rxjs marble-testing

More from Tamir Dresher (20)

PPTX
Engineering tools for making smarter decisions .pptx
PDF
NET Aspire - NET Conf IL 2024 - Tamir Dresher.pdf
PPTX
Tamir Dresher - DotNet 7 What's new.pptx
PPTX
Tamir Dresher - What’s new in ASP.NET Core 6
PPTX
Tamir Dresher - Async Streams in C#
PPTX
Anatomy of a data driven architecture - Tamir Dresher
PPTX
Tamir Dresher Clarizen adventures with the wild GC during the holiday season
PDF
Debugging tricks you wish you knew Tamir Dresher - Odessa 2019
PDF
From zero to hero with the actor model - Tamir Dresher - Odessa 2019
PPTX
Tamir Dresher - Demystifying the Core of .NET Core
PPTX
Breaking the monolith to microservice with Docker and Kubernetes (k8s)
PPTX
.Net december 2017 updates - Tamir Dresher
PPTX
Debugging tricks you wish you knew - Tamir Dresher
PPTX
Cloud patterns - NDC Oslo 2016 - Tamir Dresher
PPTX
Reactiveness All The Way - SW Architecture 2015 Conference
PPTX
Leveraging Dependency Injection(DI) in Universal Applications - Tamir Dresher
PPTX
Where Is My Data - ILTAM Session
PPT
Azure Cloud Patterns
PPT
Building services running on Microsoft Azure
PPTX
Where is my data (in the cloud) tamir dresher
Engineering tools for making smarter decisions .pptx
NET Aspire - NET Conf IL 2024 - Tamir Dresher.pdf
Tamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher - Async Streams in C#
Anatomy of a data driven architecture - Tamir Dresher
Tamir Dresher Clarizen adventures with the wild GC during the holiday season
Debugging tricks you wish you knew Tamir Dresher - Odessa 2019
From zero to hero with the actor model - Tamir Dresher - Odessa 2019
Tamir Dresher - Demystifying the Core of .NET Core
Breaking the monolith to microservice with Docker and Kubernetes (k8s)
.Net december 2017 updates - Tamir Dresher
Debugging tricks you wish you knew - Tamir Dresher
Cloud patterns - NDC Oslo 2016 - Tamir Dresher
Reactiveness All The Way - SW Architecture 2015 Conference
Leveraging Dependency Injection(DI) in Universal Applications - Tamir Dresher
Where Is My Data - ILTAM Session
Azure Cloud Patterns
Building services running on Microsoft Azure
Where is my data (in the cloud) tamir dresher

Recently uploaded (20)

PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PPTX
L1 - Introduction to python Backend.pptx
PDF
top salesforce developer skills in 2025.pdf
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PDF
Nekopoi APK 2025 free lastest update
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PDF
AI in Product Development-omnex systems
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PPTX
ai tools demonstartion for schools and inter college
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PPTX
Online Work Permit System for Fast Permit Processing
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Odoo Companies in India – Driving Business Transformation.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Internet Downloader Manager (IDM) Crack 6.42 Build 41
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
L1 - Introduction to python Backend.pptx
top salesforce developer skills in 2025.pdf
VVF-Customer-Presentation2025-Ver1.9.pptx
Transform Your Business with a Software ERP System
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Nekopoi APK 2025 free lastest update
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
AI in Product Development-omnex systems
Design an Analysis of Algorithms I-SECS-1021-03
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
ai tools demonstartion for schools and inter college
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Online Work Permit System for Fast Permit Processing
ISO 45001 Occupational Health and Safety Management System
Odoo Companies in India – Driving Business Transformation.pdf

Rx 101 - Tamir Dresher - Copenhagen .NET User Group

Editor's Notes

  • #3: My name is tamir dresher Im an architect from codevalue israel and a software engineering lecturer at the ruppin academic center CodeValue is a consulting company and we are also the proud development center of OzCode the amazing debugging extension for visual studio. We have a booth here at conference, so please go and check it out, youll be amazed how you lived without it. My book Rx in action is now available at Manning early access program should be published in the next few months. And that the end of my self promotion(it never hurts right?). So what are we really here for?
  • #7: Breakpoints conditional breakpoints Comparing object while debugging Object IDs OzCode Compare Exceptions Breaking on exceptions Conditional exceptions break Debugging Multithreaded Applications Freezing debugging to the current thread detecting deadlocked tasks Using tracepoints Finding an object and seeing all object of certain type while debugging Debugging LINQ Post-mortum debugging Dumps
  • #16: Since .net 4