Upload
peter-bons
View
73
Download
0
Embed Size (px)
Citation preview
Member of the stack since 2009
Why Reactive Programming?
Events vs Rx: Why Rx is a better model.
• In C#, events have a curious interface. Some find the += and -= operators an unnatural way to register a callback
• Events are difficult to compose• Events do not offer the ability to be easily queried over time• Events are a common cause of accidental memory leaks• Events do not have a standard pattern for signaling completion• Events provide almost no help for concurrency or multithreaded applications.
For instance, raising an event on a separate thread requires you to do all of the plumbing
Events vs Rx
Events vs Rx
Events vs Rx
Events vs Rx
Creating an Observable
• Custom using a Subject<T>
• Based on Event (FromEventPattern)
• Several other options:
– ToObservable()
– Observable.Interval(TimeSpan ts)
– Observable.Create(…)
– Many more…
Demo - Query over Time
ApplicationLogger.Instance.Write(…)
event EventHandler<EvArgs> LogEntryWritten
Question:
How to get a signal when a certain log entry occurs more than (n) times in a given time period?
Demo – Composition
FileSystemWatcher
- Deleted event
- Created event
Question:
How would I scan for creates and deletes that have occurred every (n) minutes?
Demo – Threading
SomeEvent(Object sender, SomeEventArgs e){
PerformWorkTaking10Seconds (e)UpdateUi(e)
}_______________________________________________________________
OnSomeEvent(){
if(SomeEvent != null)SomeEvent(this, new SomeEventArgs());
}
With (n) subscribers, how long does it take to complete OnSomeEvent()?
Other Goodies
• React to UI (demo)
• Timeout (demo)
• Lots of Operators
– Where()
– Retry()
– Amb()
– OnErrorResumeNext()
– …
Usages in PlanCare 2
• Buffering Web Api Request logentries
• Handling Notifications (Buffer, Transform)
• As Event Substitute in Business Layer
And more: PHP, Pearl, Haskeel
http://nflx.it/1yR60gV
http://bit.ly/1LOtiH3
http://bit.ly/1E2WpqT
http://bit.ly/1E3dscb
What’s Next?
IQbservable<T> - Linq to ServicesSubscribe to changes somewhere else
Get started …
• http://www.introtorx.com/
• http://rxwiki.wikidot.com/101samples
• http://t.co/gB7SPIcZu3 (Must See!)
… play … and remember:Often it is not the technique that let's us down, but our implementation of it.