Code to accompany Intro to Reactive extentions talk
#LinqPad Demos
- [BackgroundThread](LinqPadSamples/01 BackgroundThread.linq)
- [ThreadSafe](LinqPadSamples/01 ThreadSafe.linq)
- [ColdEnumerable]("LinqPadSamples/02 ColdEnumerable.linq")
- [ColdObservable]("LinqPadSamples/03 ColdObservable.linq")
- [HotObservable]("LinqPadSamples/04 HotObservable.linq")
- [Create]("LinqPadSamples/06 Create.linq")
- [CreateDisposable]("LinqPadSamples/06 CreateDisposable.linq")
- [GenerateWithTime]("LinqPadSamples/07 GenerateWithTime.linq")
- A slow or expensive query
- On a background loop
- With user initiated action, for the impatient
- But not too often
- Compare the ad-hoc w/ the Rx approach
###UI for password check
- Accept correct password
- Reject incorrect
- No "submit button"
- Timeout
- Must be unit testable
- Need to make an IO from a traditional API
- Want a mock version for UI development
- Only want to show latest for each user
- Want late subscribers to have latest values
- What's the Rx thing about, why should I care?
- Will it make my life easier?
- What's new in 1.0
- For some, Rx is something of a revelation.
- A good way to deal with asynchronous code
- A good way to deal with event based code
- A good way to deal with concurrent code
- A good way to deal with time sensitive code
-
Systems and architectures that are not reactive are legacy systems
- Real life is async
- Sync, ie, blocking activities are souces of real stress
- waiting in line for coffee, the elevator, the check to clear, etc
-
Batch, pull, polling, request/response were common b/c building asyncronous code was (much) harder
-
Till now...
- Composable
- Testable
- Pure (side-effect free)
###Two use cases
- Managing a bar
- Calling a web service async
- A new Interface pair
IObservable<T>
andIObserver<T>
for .Net BCL- The dual of
IEnumerable<T>
andIEnumerator<T>
- The dual of
- A core implementation and a set of Linq combinators for doing useful things
- Detect "double tap" on a smartphone
- Update on maximum value reached (price, diskspace, water volume, temp, etc)
- Detecting if a server went down
interface IEnumerable<T>
{
IEnumerator<T> GetEnumerator();
}
interface IEnumerator<T>: IDisposable
{
T Current { get; }
bool MoveNext();
}
interface IObservable<T>
{
IDisposable Subscribe(IObserver<T> observer);
}
interface IObserver<T>
{
void OnCompleted();
void OnError(Exception error);
void OnNext(T value);
}
new[] { 1, 2, 3, 4 }
new List<string>()
Enumerable.Range(1, Int32.MaxValue)
new int[Int32.MaxValue]
People.Where(pers => pers.Age >= 21)
Observable.Range(1,3)
Observable.FromEvent("Click")
- Avoid implementing IObservable from scratch
- Hot or not?