SlideShare ist ein Scribd-Unternehmen logo
1 von 30
Reactive Extensions (RX)
Tamir Dresher
Senior Software Architect
June 19, 2013
Slides: Bart De Smet
About Me
•
•
•
•
•

Software architect, consultant and instructor
Technology addict
10 years of experience
.NET and Native Windows Programming
http://www.TamirDresher.com.
Applications And Data
GPS

RSS

feeds

Social
media

Server management
Recovery
Projection
Aggregating

from quote in stock
where quote.Symbol == “MSFT”
select quote.Value

IObservable<T>

IScheduler

Windowing
Sampling
Sharing
Throttling
Merging

Joins

Filtering
Grouping

Reactive Extensions Architecture

Timeout

ISubject<T>

IObserver<T>
The building blocks
• Observables
– Producers (.NET events, WinRT Events, Sensors, APM method etc.)

• Observers
– Consumers

Observable
Subscribe

Observer
Essential Interfaces
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();
}
}
Notification Grammar
OnNext(42)

OnNext(43)

OnNext(“Hello”)

OnNext

OnCompleted

OnError(error)

OnError OnCompleted
Limitations of .NET Events
exchange.StockTick += (sender, args) =>
{
if (args.Quote.Symbol == “MSFT”)
{
// Imperative code
}
};
exchange.StockTick -= /* what goes here? */;
Observable Sequences to the Rescue
IObservable<Quote> stockQuotes = …;
var msft = stockQuotes

.Where(quote => quote.Symbol == “MSFT”);
var subscription = msft.Subscribe(quote => /* … */);

subscription.Dispose();
Dictionary Suggest
Asynchronous
request
React

Dictionary web
service

Reaction
Reactive
Reactor

Data binding
on UI thread
Demo
Converting Events and Asynchronous Methods
// Convert the TextChanged event to IObservable<string>
var input = (from evt in Observable.FromEventPattern(txt, “TextChanged”)
select ((TextBox)evt.Sender).Text)
.Throttle(TimeSpan.FromSeconds(0.5))
.DistinctUntilChanged();
// Convert asynchronous proxy methods to Func<string, IObservable<string[]>>
var lookup = Observable.FromAsyncPattern<string, string[]>(svc.BeginLookup,
svc.EndLookup);

// Compose both sources using a query
var res = from term in input
from words in lookup(term).TakeUntil(input)
select words;
Stock Trade Analysis
MSFT
27.01

INTC
21.75

from tick in ticks

MSFT
27.96

MSFT
31.21

INTC
22.54

INTC
20.98

MSFT
30.73
Stock Trade Analysis
MSFT
27.01

INTC
21.75

MSFT
27.96

27.01

MSFT
31.21

27.96

21.75

from tick in ticks

group tick by tick.Symbol into company

INTC
22.54

INTC
20.98

MSFT
30.73

30.73

31.21

22.54

20.98
Stock Trade Analysis
MSFT
27.01

INTC
21.75

MSFT
27.96

[27.01, 27.96]

MSFT
31.21

INTC
22.54

INTC
20.98

[27.96, 31.21]

[31.21, 30.73]

[21.75, 22.54]

from tick in ticks

group tick by tick.Symbol into company
from openClose in company.Buffer(2, 1)

MSFT
30.73

[22.54, 20.98]
Stock Trade Analysis
MSFT
27.01

INTC
21.75

MSFT
27.96

MSFT
31.21

0.034

INTC
22.54

INTC
20.98

0.104

MSFT
30.73

-0.015

0.036

-0.069

from tick in ticks
group tick by tick.Symbol into company
from openClose in company.Buffer(2, 1)

let diff = (openClose[1] – openClose[0]) / openClose[0]
Stock Trade Analysis
MSFT
27.01

INTC
21.75

MSFT
27.96

MSFT
31.21

0.034

INTC
22.54

0.104

where diff > 0.1

MSFT
30.73

-0.015

0.036

from tick in ticks
group tick by tick.Symbol into company
from openClose in company.Buffer(2, 1)
let diff = (openClose[1] – openClose[0]) / openClose[0]

INTC
20.98

-0.069
Stock Trade Analysis
MSFT
27.01

INTC
21.75

MSFT
27.96

MSFT
31.21

INTC
22.54

Company = MSFT
Increase = 0.104
from tick in ticks
group tick by tick.Symbol into company
from openClose in company.Buffer(2, 1)
let diff = (openClose[1] – openClose[0]) / openClose[0]
where diff > 0.1

select new { Company = company.Key, Increase = diff }

INTC
20.98

MSFT
30.73
Reactive Extensions Architecture

IScheduler
The Role of Schedulers
Parameterize Concurrency
//
// Runs a timer on the default scheduler
//
IObservable long
TimeSpan
//
// Every operator that introduces concurrency
// has an overload with an IScheduler
//
IObservable long
TimeSpan
IScheduler scheduler
The Role of Schedulers
var

Observable.Return

Scheduler.ThreadPool
"Answer = "

xs.ObserveOn(
frm )
xs.ObserveOn(new ControlScheduler(frm))
.Subscribe(x => lbl.Text = "Answer = " + x);
The IScheduler Interface
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);
}
Operational Layering of Rx
public static IObservable<T> Return<T>(T value,
IScheduler scheduler)
{
return Observable.Create<T>(observer =>
{
// Serialize state to scheduler; return ability to cancel
return scheduler.Schedule(new { value, observer }, (_, x) =>
{
x.observer.OnNext(x.value);
x.observer.OnCompleted();
return Disposable.Empty; // No recursive work
});
});
}
Virtualizing Time for Testing
var scheduler = new TestScheduler();
var input = scheduler.CreateHotObservable(
OnNext(300, “Bart De Smet”),
OnNext(400, “Erik Meijer”),
OnCompleted<string>(500)
);
var results = scheduler.Start(() => from name in input
select name.Length);

results.Messages.AssertEqual(
OnNext(300, 12),
OnNext(400, 11),
OnCompleted<int>(500)
);
The Asynchronous Programming Landscape
Summary
• Tame your event streams using Rx and LINQ!
• Download Rx today!
– Through http://www.microsoft.com/download (search for Rx SDK)
– Using NuGet @ www.nuget.org (search for Rx-Main)
• Watch videos at http://channel9.msdn.com/tags/Rx
Related Content
RxJS
/* Only get the value from each key up */
var keyups = Rx.Observable.fromEvent(input, 'keyup')
.select(function (e) {
return e.target.value;
})
.where(function (text) {
return text.length > 2;
});
/* Now throttle/debounce the input for 500ms */
var throttled = keyups
.throttle(500 /* ms */);
/* Now get only distinct values, so we eliminate the arrows */
var distinct = keyups
.distinctUntilChanged();

RX++
void PrintPrimes(int n)
{
std::cout<<"Rx: first "<<n<<" primes squared"<<endl;
auto values = rxcpp::Range(2);
rxcpp::from(values)
.where(IsPrime)
.select([](int x) { return std::make_pair(x, x*x); })
.take(n)
.for_each(rxcpp::MakeTupleDispatch(
[](int p, int s)
{
cout<<p<<" =square=> "<<s<<endl;
}));
}
ReactiveUI
public class NewUserViewModel : ReactiveObject
{
// This is ReactiveUI's version of implementing INotifyPropertyChanged
string _Password,_PasswordConfirmation;
public string Password {
get { return _Password; }
set { this.RaiseAndSetIfChanged(x => x.Password, value); }
}
public string PasswordConfirmation {
get { return _PasswordConfirmation; }
set { this.RaiseAndSetIfChanged(x => x.PasswordConfirmation, value); }
}
ICommand OkCommand { get; protected set; }
public NewUserViewModel()
{
var canHitOk = this.WhenAny(
x => x.Password,
x => x.PasswordConfirmation,
(pass, confirm) => (pass.Value == confirm.Value && pass.Value.Length > 3));
OkCommand = new ReactiveCommand(canHitOk);
}
28
Resources
• Channel 9
– Curing Your Event Processing Blues with Reactive Extensions (Rx) Bart De Smet
http://msdn.microsoft.com/enus/library/windowsazure/jj860549.aspx

• IntroToRx.com
– IntroToRx.com is the online resource for getting started with
the Reactive Extensions to .Net.

• www.reactiveui.com
https://github.com/reactiveui/ReactiveUI.Samples
Presenter contact details
c: +972-52-4772946
e: tamirdr@codevalue.net
b: TamirDresher.com
w: www.codevalue.net

Weitere ähnliche Inhalte

Was ist angesagt?

Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbookManusha Dilan
 
New Java Date/Time API
New Java Date/Time APINew Java Date/Time API
New Java Date/Time APIJuliet Nkwor
 
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)Agile Lietuva
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance PuzzlersDoug Hawkins
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL fileRACHIT_GUPTA
 
Rx for Android & iOS by Harin Trivedi
Rx for Android & iOS  by Harin TrivediRx for Android & iOS  by Harin Trivedi
Rx for Android & iOS by Harin Trivediharintrivedi
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroidSavvycom Savvycom
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Intel® Software
 
Art of unit testing: How developer should care about code quality
Art of unit testing: How developer should care about code qualityArt of unit testing: How developer should care about code quality
Art of unit testing: How developer should care about code qualityDmytro Patserkovskyi
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical FileSoumya Behera
 
Machine Learning Model Bakeoff
Machine Learning Model BakeoffMachine Learning Model Bakeoff
Machine Learning Model Bakeoffmrphilroth
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife SpringMario Fusco
 

Was ist angesagt? (20)

Base de-datos
Base de-datosBase de-datos
Base de-datos
 
Java_practical_handbook
Java_practical_handbookJava_practical_handbook
Java_practical_handbook
 
Spock framework
Spock frameworkSpock framework
Spock framework
 
New Java Date/Time API
New Java Date/Time APINew Java Date/Time API
New Java Date/Time API
 
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
Tieto tdd from-dreams_to_reality_s.narkevicius_v.pozdniakov_2013 (1)
 
Rxjs ppt
Rxjs pptRxjs ppt
Rxjs ppt
 
Java Performance Puzzlers
Java Performance PuzzlersJava Performance Puzzlers
Java Performance Puzzlers
 
Java practical
Java practicalJava practical
Java practical
 
Java PRACTICAL file
Java PRACTICAL fileJava PRACTICAL file
Java PRACTICAL file
 
Rx for Android & iOS by Harin Trivedi
Rx for Android & iOS  by Harin TrivediRx for Android & iOS  by Harin Trivedi
Rx for Android & iOS by Harin Trivedi
 
Hadoop Puzzlers
Hadoop PuzzlersHadoop Puzzlers
Hadoop Puzzlers
 
Spock Framework
Spock FrameworkSpock Framework
Spock Framework
 
Reactive programming with RxAndroid
Reactive programming with RxAndroidReactive programming with RxAndroid
Reactive programming with RxAndroid
 
Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*Tools and Techniques for Understanding Threading Behavior in Android*
Tools and Techniques for Understanding Threading Behavior in Android*
 
Art of unit testing: How developer should care about code quality
Art of unit testing: How developer should care about code qualityArt of unit testing: How developer should care about code quality
Art of unit testing: How developer should care about code quality
 
JVM Mechanics
JVM MechanicsJVM Mechanics
JVM Mechanics
 
Rxjs vienna
Rxjs viennaRxjs vienna
Rxjs vienna
 
Advanced Java Practical File
Advanced Java Practical FileAdvanced Java Practical File
Advanced Java Practical File
 
Machine Learning Model Bakeoff
Machine Learning Model BakeoffMachine Learning Model Bakeoff
Machine Learning Model Bakeoff
 
Swiss army knife Spring
Swiss army knife SpringSwiss army knife Spring
Swiss army knife Spring
 

Ähnlich wie Introduction to Reactive Extensions (Rx)

Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityDefconRussia
 
Ekon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side NotificationsEkon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side NotificationsArnaud Bouchez
 
SQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cSQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cRachelBarker26
 
Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11Matt Warren
 
With big data comes big responsibility
With big data comes big responsibilityWith big data comes big responsibility
With big data comes big responsibilityERPScan
 
Where the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsMatt Warren
 
Windows Remote Management - EN
Windows Remote Management - ENWindows Remote Management - EN
Windows Remote Management - ENKirill Nikolaev
 
Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Matt Warren
 
New Zephyr features: LWM2M / FOTA Framework - SFO17-113
New Zephyr features: LWM2M / FOTA Framework - SFO17-113New Zephyr features: LWM2M / FOTA Framework - SFO17-113
New Zephyr features: LWM2M / FOTA Framework - SFO17-113Linaro
 
Advanced iOS Build Mechanics, Sebastien Pouliot
Advanced iOS Build Mechanics, Sebastien PouliotAdvanced iOS Build Mechanics, Sebastien Pouliot
Advanced iOS Build Mechanics, Sebastien PouliotXamarin
 
Observability and its application
Observability and its applicationObservability and its application
Observability and its applicationThao Huynh Quang
 
Apache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapApache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapKostas Tzoumas
 
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
22-4_PerformanceTuningUsingtheAdvisorFramework.pdfyishengxi
 
Reactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and RxReactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and RxSumant Tambe
 
Capacity Planning for Linux Systems
Capacity Planning for Linux SystemsCapacity Planning for Linux Systems
Capacity Planning for Linux SystemsRodrigo Campos
 

Ähnlich wie Introduction to Reactive Extensions (Rx) (20)

Georgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software securityGeorgy Nosenko - An introduction to the use SMT solvers for software security
Georgy Nosenko - An introduction to the use SMT solvers for software security
 
Ekon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side NotificationsEkon25 mORMot 2 Server-Side Notifications
Ekon25 mORMot 2 Server-Side Notifications
 
SQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19cSQL Performance Tuning and New Features in Oracle 19c
SQL Performance Tuning and New Features in Oracle 19c
 
Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11Performance is a Feature! at DDD 11
Performance is a Feature! at DDD 11
 
With big data comes big responsibility
With big data comes big responsibilityWith big data comes big responsibility
With big data comes big responsibility
 
Where the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-OptimisationsWhere the wild things are - Benchmarking and Micro-Optimisations
Where the wild things are - Benchmarking and Micro-Optimisations
 
Windows Remote Management - EN
Windows Remote Management - ENWindows Remote Management - EN
Windows Remote Management - EN
 
Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016Performance and how to measure it - ProgSCon London 2016
Performance and how to measure it - ProgSCon London 2016
 
Performance is a Feature!
Performance is a Feature!Performance is a Feature!
Performance is a Feature!
 
New Zephyr features: LWM2M / FOTA Framework - SFO17-113
New Zephyr features: LWM2M / FOTA Framework - SFO17-113New Zephyr features: LWM2M / FOTA Framework - SFO17-113
New Zephyr features: LWM2M / FOTA Framework - SFO17-113
 
Tdd,Ioc
Tdd,IocTdd,Ioc
Tdd,Ioc
 
Advanced iOS Build Mechanics, Sebastien Pouliot
Advanced iOS Build Mechanics, Sebastien PouliotAdvanced iOS Build Mechanics, Sebastien Pouliot
Advanced iOS Build Mechanics, Sebastien Pouliot
 
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop  - Xi...
PMED Undergraduate Workshop - R Tutorial for PMED Undegraduate Workshop - Xi...
 
Observability and its application
Observability and its applicationObservability and its application
Observability and its application
 
Apache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmapApache Flink: API, runtime, and project roadmap
Apache Flink: API, runtime, and project roadmap
 
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
 
Software Engineering
Software EngineeringSoftware Engineering
Software Engineering
 
Learning Dtrace
Learning DtraceLearning Dtrace
Learning Dtrace
 
Reactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and RxReactive Stream Processing Using DDS and Rx
Reactive Stream Processing Using DDS and Rx
 
Capacity Planning for Linux Systems
Capacity Planning for Linux SystemsCapacity Planning for Linux Systems
Capacity Planning for Linux Systems
 

Mehr von Tamir Dresher

NET Aspire - NET Conf IL 2024 - Tamir Dresher.pdf
NET Aspire - NET Conf IL 2024 - Tamir Dresher.pdfNET Aspire - NET Conf IL 2024 - Tamir Dresher.pdf
NET Aspire - NET Conf IL 2024 - Tamir Dresher.pdfTamir Dresher
 
Tamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - DotNet 7 What's new.pptxTamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - DotNet 7 What's new.pptxTamir Dresher
 
Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher - What’s new in ASP.NET Core 6Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher - What’s new in ASP.NET Core 6Tamir Dresher
 
Tamir Dresher - Async Streams in C#
Tamir Dresher - Async Streams in C#Tamir Dresher - Async Streams in C#
Tamir Dresher - Async Streams in C#Tamir Dresher
 
Anatomy of a data driven architecture - Tamir Dresher
Anatomy of a data driven architecture - Tamir Dresher   Anatomy of a data driven architecture - Tamir Dresher
Anatomy of a data driven architecture - Tamir Dresher Tamir Dresher
 
Tamir Dresher Clarizen adventures with the wild GC during the holiday season
Tamir Dresher   Clarizen adventures with the wild GC during the holiday seasonTamir Dresher   Clarizen adventures with the wild GC during the holiday season
Tamir Dresher Clarizen adventures with the wild GC during the holiday seasonTamir Dresher
 
Debugging tricks you wish you knew Tamir Dresher - Odessa 2019
Debugging tricks you wish you knew   Tamir Dresher - Odessa 2019Debugging tricks you wish you knew   Tamir Dresher - Odessa 2019
Debugging tricks you wish you knew Tamir Dresher - Odessa 2019Tamir Dresher
 
From zero to hero with the actor model - Tamir Dresher - Odessa 2019
From zero to hero with the actor model  - Tamir Dresher - Odessa 2019From zero to hero with the actor model  - Tamir Dresher - Odessa 2019
From zero to hero with the actor model - Tamir Dresher - Odessa 2019Tamir Dresher
 
Tamir Dresher - Demystifying the Core of .NET Core
Tamir Dresher  - Demystifying the Core of .NET CoreTamir Dresher  - Demystifying the Core of .NET Core
Tamir Dresher - Demystifying the Core of .NET CoreTamir Dresher
 
Breaking the monolith to microservice with Docker and Kubernetes (k8s)
Breaking the monolith to microservice with Docker and Kubernetes (k8s)Breaking the monolith to microservice with Docker and Kubernetes (k8s)
Breaking the monolith to microservice with Docker and Kubernetes (k8s)Tamir Dresher
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir DresherTamir Dresher
 
Testing time and concurrency Rx
Testing time and concurrency RxTesting time and concurrency Rx
Testing time and concurrency RxTamir Dresher
 
.NET Debugging tricks you wish you knew tamir dresher
.NET Debugging tricks you wish you knew   tamir dresher.NET Debugging tricks you wish you knew   tamir dresher
.NET Debugging tricks you wish you knew tamir dresherTamir Dresher
 
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir DresherFrom Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir DresherTamir Dresher
 
Debugging tricks you wish you knew - Tamir Dresher
Debugging tricks you wish you knew  - Tamir DresherDebugging tricks you wish you knew  - Tamir Dresher
Debugging tricks you wish you knew - Tamir DresherTamir Dresher
 
Rx 101 - Tamir Dresher - Copenhagen .NET User Group
Rx 101  - Tamir Dresher - Copenhagen .NET User GroupRx 101  - Tamir Dresher - Copenhagen .NET User Group
Rx 101 - Tamir Dresher - Copenhagen .NET User GroupTamir Dresher
 
Cloud patterns - NDC Oslo 2016 - Tamir Dresher
Cloud patterns - NDC Oslo 2016 - Tamir DresherCloud patterns - NDC Oslo 2016 - Tamir Dresher
Cloud patterns - NDC Oslo 2016 - Tamir DresherTamir Dresher
 
Reactiveness All The Way - SW Architecture 2015 Conference
Reactiveness All The Way - SW Architecture 2015 ConferenceReactiveness All The Way - SW Architecture 2015 Conference
Reactiveness All The Way - SW Architecture 2015 ConferenceTamir Dresher
 
Leveraging Dependency Injection(DI) in Universal Applications - Tamir Dresher
Leveraging Dependency Injection(DI) in Universal Applications -  Tamir DresherLeveraging Dependency Injection(DI) in Universal Applications -  Tamir Dresher
Leveraging Dependency Injection(DI) in Universal Applications - Tamir DresherTamir Dresher
 
Where Is My Data - ILTAM Session
Where Is My Data - ILTAM SessionWhere Is My Data - ILTAM Session
Where Is My Data - ILTAM SessionTamir Dresher
 

Mehr von Tamir Dresher (20)

NET Aspire - NET Conf IL 2024 - Tamir Dresher.pdf
NET Aspire - NET Conf IL 2024 - Tamir Dresher.pdfNET Aspire - NET Conf IL 2024 - Tamir Dresher.pdf
NET Aspire - NET Conf IL 2024 - Tamir Dresher.pdf
 
Tamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - DotNet 7 What's new.pptxTamir Dresher - DotNet 7 What's new.pptx
Tamir Dresher - DotNet 7 What's new.pptx
 
Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher - What’s new in ASP.NET Core 6Tamir Dresher - What’s new in ASP.NET Core 6
Tamir Dresher - What’s new in ASP.NET Core 6
 
Tamir Dresher - Async Streams in C#
Tamir Dresher - Async Streams in C#Tamir Dresher - Async Streams in C#
Tamir Dresher - Async Streams in C#
 
Anatomy of a data driven architecture - Tamir Dresher
Anatomy of a data driven architecture - Tamir Dresher   Anatomy of a data driven architecture - Tamir Dresher
Anatomy of a data driven architecture - Tamir Dresher
 
Tamir Dresher Clarizen adventures with the wild GC during the holiday season
Tamir Dresher   Clarizen adventures with the wild GC during the holiday seasonTamir Dresher   Clarizen adventures with the wild GC during the holiday season
Tamir Dresher Clarizen adventures with the wild GC during the holiday season
 
Debugging tricks you wish you knew Tamir Dresher - Odessa 2019
Debugging tricks you wish you knew   Tamir Dresher - Odessa 2019Debugging tricks you wish you knew   Tamir Dresher - Odessa 2019
Debugging tricks you wish you knew Tamir Dresher - Odessa 2019
 
From zero to hero with the actor model - Tamir Dresher - Odessa 2019
From zero to hero with the actor model  - Tamir Dresher - Odessa 2019From zero to hero with the actor model  - Tamir Dresher - Odessa 2019
From zero to hero with the actor model - Tamir Dresher - Odessa 2019
 
Tamir Dresher - Demystifying the Core of .NET Core
Tamir Dresher  - Demystifying the Core of .NET CoreTamir Dresher  - Demystifying the Core of .NET Core
Tamir Dresher - Demystifying the Core of .NET Core
 
Breaking the monolith to microservice with Docker and Kubernetes (k8s)
Breaking the monolith to microservice with Docker and Kubernetes (k8s)Breaking the monolith to microservice with Docker and Kubernetes (k8s)
Breaking the monolith to microservice with Docker and Kubernetes (k8s)
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher
 
Testing time and concurrency Rx
Testing time and concurrency RxTesting time and concurrency Rx
Testing time and concurrency Rx
 
.NET Debugging tricks you wish you knew tamir dresher
.NET Debugging tricks you wish you knew   tamir dresher.NET Debugging tricks you wish you knew   tamir dresher
.NET Debugging tricks you wish you knew tamir dresher
 
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir DresherFrom Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
From Zero to the Actor Model (With Akka.Net) - CodeMash2017 - Tamir Dresher
 
Debugging tricks you wish you knew - Tamir Dresher
Debugging tricks you wish you knew  - Tamir DresherDebugging tricks you wish you knew  - Tamir Dresher
Debugging tricks you wish you knew - Tamir Dresher
 
Rx 101 - Tamir Dresher - Copenhagen .NET User Group
Rx 101  - Tamir Dresher - Copenhagen .NET User GroupRx 101  - Tamir Dresher - Copenhagen .NET User Group
Rx 101 - Tamir Dresher - Copenhagen .NET User Group
 
Cloud patterns - NDC Oslo 2016 - Tamir Dresher
Cloud patterns - NDC Oslo 2016 - Tamir DresherCloud patterns - NDC Oslo 2016 - Tamir Dresher
Cloud patterns - NDC Oslo 2016 - Tamir Dresher
 
Reactiveness All The Way - SW Architecture 2015 Conference
Reactiveness All The Way - SW Architecture 2015 ConferenceReactiveness All The Way - SW Architecture 2015 Conference
Reactiveness All The Way - SW Architecture 2015 Conference
 
Leveraging Dependency Injection(DI) in Universal Applications - Tamir Dresher
Leveraging Dependency Injection(DI) in Universal Applications -  Tamir DresherLeveraging Dependency Injection(DI) in Universal Applications -  Tamir Dresher
Leveraging Dependency Injection(DI) in Universal Applications - Tamir Dresher
 
Where Is My Data - ILTAM Session
Where Is My Data - ILTAM SessionWhere Is My Data - ILTAM Session
Where Is My Data - ILTAM Session
 

Kürzlich hochgeladen

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterMydbops
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...itnewsafrica
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPathCommunity
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesManik S Magar
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...itnewsafrica
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 

Kürzlich hochgeladen (20)

A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Scale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL RouterScale your database traffic with Read & Write split using MySQL Router
Scale your database traffic with Read & Write split using MySQL Router
 
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...Abdul Kader Baba- Managing Cybersecurity Risks  and Compliance Requirements i...
Abdul Kader Baba- Managing Cybersecurity Risks and Compliance Requirements i...
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 
UiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to HeroUiPath Community: Communication Mining from Zero to Hero
UiPath Community: Communication Mining from Zero to Hero
 
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotesMuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
MuleSoft Online Meetup Group - B2B Crash Course: Release SparkNotes
 
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...Zeshan Sattar- Assessing the skill requirements and industry expectations for...
Zeshan Sattar- Assessing the skill requirements and industry expectations for...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 

Introduction to Reactive Extensions (Rx)

  • 1. Reactive Extensions (RX) Tamir Dresher Senior Software Architect June 19, 2013 Slides: Bart De Smet
  • 2. About Me • • • • • Software architect, consultant and instructor Technology addict 10 years of experience .NET and Native Windows Programming http://www.TamirDresher.com.
  • 4. Recovery Projection Aggregating from quote in stock where quote.Symbol == “MSFT” select quote.Value IObservable<T> IScheduler Windowing Sampling Sharing Throttling Merging Joins Filtering Grouping Reactive Extensions Architecture Timeout ISubject<T> IObserver<T>
  • 5. The building blocks • Observables – Producers (.NET events, WinRT Events, Sensors, APM method etc.) • Observers – Consumers Observable Subscribe Observer
  • 6. Essential Interfaces 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(); } }
  • 8. Limitations of .NET Events exchange.StockTick += (sender, args) => { if (args.Quote.Symbol == “MSFT”) { // Imperative code } }; exchange.StockTick -= /* what goes here? */;
  • 9. Observable Sequences to the Rescue IObservable<Quote> stockQuotes = …; var msft = stockQuotes .Where(quote => quote.Symbol == “MSFT”); var subscription = msft.Subscribe(quote => /* … */); subscription.Dispose();
  • 11. Demo
  • 12. Converting Events and Asynchronous Methods // Convert the TextChanged event to IObservable<string> var input = (from evt in Observable.FromEventPattern(txt, “TextChanged”) select ((TextBox)evt.Sender).Text) .Throttle(TimeSpan.FromSeconds(0.5)) .DistinctUntilChanged(); // Convert asynchronous proxy methods to Func<string, IObservable<string[]>> var lookup = Observable.FromAsyncPattern<string, string[]>(svc.BeginLookup, svc.EndLookup); // Compose both sources using a query var res = from term in input from words in lookup(term).TakeUntil(input) select words;
  • 13. Stock Trade Analysis MSFT 27.01 INTC 21.75 from tick in ticks MSFT 27.96 MSFT 31.21 INTC 22.54 INTC 20.98 MSFT 30.73
  • 14. Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 27.01 MSFT 31.21 27.96 21.75 from tick in ticks group tick by tick.Symbol into company INTC 22.54 INTC 20.98 MSFT 30.73 30.73 31.21 22.54 20.98
  • 15. Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 [27.01, 27.96] MSFT 31.21 INTC 22.54 INTC 20.98 [27.96, 31.21] [31.21, 30.73] [21.75, 22.54] from tick in ticks group tick by tick.Symbol into company from openClose in company.Buffer(2, 1) MSFT 30.73 [22.54, 20.98]
  • 16. Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 0.034 INTC 22.54 INTC 20.98 0.104 MSFT 30.73 -0.015 0.036 -0.069 from tick in ticks group tick by tick.Symbol into company from openClose in company.Buffer(2, 1) let diff = (openClose[1] – openClose[0]) / openClose[0]
  • 17. Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 0.034 INTC 22.54 0.104 where diff > 0.1 MSFT 30.73 -0.015 0.036 from tick in ticks group tick by tick.Symbol into company from openClose in company.Buffer(2, 1) let diff = (openClose[1] – openClose[0]) / openClose[0] INTC 20.98 -0.069
  • 18. Stock Trade Analysis MSFT 27.01 INTC 21.75 MSFT 27.96 MSFT 31.21 INTC 22.54 Company = MSFT Increase = 0.104 from tick in ticks group tick by tick.Symbol into company from openClose in company.Buffer(2, 1) let diff = (openClose[1] – openClose[0]) / openClose[0] where diff > 0.1 select new { Company = company.Key, Increase = diff } INTC 20.98 MSFT 30.73
  • 20. The Role of Schedulers Parameterize Concurrency // // Runs a timer on the default scheduler // IObservable long TimeSpan // // Every operator that introduces concurrency // has an overload with an IScheduler // IObservable long TimeSpan IScheduler scheduler
  • 21. The Role of Schedulers var Observable.Return Scheduler.ThreadPool "Answer = " xs.ObserveOn( frm ) xs.ObserveOn(new ControlScheduler(frm)) .Subscribe(x => lbl.Text = "Answer = " + x);
  • 22. The IScheduler Interface 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); }
  • 23. Operational Layering of Rx public static IObservable<T> Return<T>(T value, IScheduler scheduler) { return Observable.Create<T>(observer => { // Serialize state to scheduler; return ability to cancel return scheduler.Schedule(new { value, observer }, (_, x) => { x.observer.OnNext(x.value); x.observer.OnCompleted(); return Disposable.Empty; // No recursive work }); }); }
  • 24. Virtualizing Time for Testing var scheduler = new TestScheduler(); var input = scheduler.CreateHotObservable( OnNext(300, “Bart De Smet”), OnNext(400, “Erik Meijer”), OnCompleted<string>(500) ); var results = scheduler.Start(() => from name in input select name.Length); results.Messages.AssertEqual( OnNext(300, 12), OnNext(400, 11), OnCompleted<int>(500) );
  • 26. Summary • Tame your event streams using Rx and LINQ! • Download Rx today! – Through http://www.microsoft.com/download (search for Rx SDK) – Using NuGet @ www.nuget.org (search for Rx-Main) • Watch videos at http://channel9.msdn.com/tags/Rx
  • 27. Related Content RxJS /* Only get the value from each key up */ var keyups = Rx.Observable.fromEvent(input, 'keyup') .select(function (e) { return e.target.value; }) .where(function (text) { return text.length > 2; }); /* Now throttle/debounce the input for 500ms */ var throttled = keyups .throttle(500 /* ms */); /* Now get only distinct values, so we eliminate the arrows */ var distinct = keyups .distinctUntilChanged(); RX++ void PrintPrimes(int n) { std::cout<<"Rx: first "<<n<<" primes squared"<<endl; auto values = rxcpp::Range(2); rxcpp::from(values) .where(IsPrime) .select([](int x) { return std::make_pair(x, x*x); }) .take(n) .for_each(rxcpp::MakeTupleDispatch( [](int p, int s) { cout<<p<<" =square=> "<<s<<endl; })); }
  • 28. ReactiveUI public class NewUserViewModel : ReactiveObject { // This is ReactiveUI's version of implementing INotifyPropertyChanged string _Password,_PasswordConfirmation; public string Password { get { return _Password; } set { this.RaiseAndSetIfChanged(x => x.Password, value); } } public string PasswordConfirmation { get { return _PasswordConfirmation; } set { this.RaiseAndSetIfChanged(x => x.PasswordConfirmation, value); } } ICommand OkCommand { get; protected set; } public NewUserViewModel() { var canHitOk = this.WhenAny( x => x.Password, x => x.PasswordConfirmation, (pass, confirm) => (pass.Value == confirm.Value && pass.Value.Length > 3)); OkCommand = new ReactiveCommand(canHitOk); } 28
  • 29. Resources • Channel 9 – Curing Your Event Processing Blues with Reactive Extensions (Rx) Bart De Smet http://msdn.microsoft.com/enus/library/windowsazure/jj860549.aspx • IntroToRx.com – IntroToRx.com is the online resource for getting started with the Reactive Extensions to .Net. • www.reactiveui.com https://github.com/reactiveui/ReactiveUI.Samples
  • 30. Presenter contact details c: +972-52-4772946 e: tamirdr@codevalue.net b: TamirDresher.com w: www.codevalue.net

Hinweis der Redaktion

  1. העולם השתנה בשנים האחרונות והאפליקציות שאנחנו מפתחים היום צריכות להיות מחוברות להמון מקורות ולקבל מידע ממידע בורסאי וכלכלי שמתעדכן בתדירות גבוהה ועד לאירועי UI וEvents סביבתיים באופן כלליהמצב קשה עוד יותר כי צריך לעשות אגרגציות על כל הנתונים ולעשות פעולות שמערבות עוד נתונים ויותר מכך, כל שירות כזה חושף API משלו שאנחנו צריכים להתאים אליוRX בא בדיוק בשביל המטרה הזו ולתת בסיס אבסטרקטי שעליו נוכל להסתכל בשביל לעבוד מול כל המקורותבסופו של דבר RX הוא Events(sobservables)+LINQ+SchedulingRX
  2. RX בנוי בצורה שכבתית (לפחות סכמטית)בבסיס יש לנו את המודל הConcurecy וה-timeמצד אחד פעולות שאנחנו עושים צריכות להתבצע במקום מסוים , בין אם thread או tasks ואפילו על גבי הענן מצד שני יש את עניין התזמון – יש שעון של המערכת, שעון dispatcher ואפילו שעון שמגיע מהרשתRX יודע לעשות אבסטרקציה לכל זהלמעלה יש לנו את צרות העבודה מול הEVENT שקורים כאשר LINQ מאפשר לנו לעשות טיפול פלואנטי עם כל היתרונות של LINQ ולהרכיב ולעשות אגרגציה על ובין אירועים. באמצע יש את הליבה שיודעת להסתכל על אירוע
  3. Observbable הוא מה שמייצג את האירוע והוא הגורם אליו אנחנו נרשמים כדי לקבל את הנוטיפקציה שהאירוע התרחשObservers הם הדברים שמאזינים לאירוע