11PluseHelp / Rx-Demo

Reactive Extensions code demos

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

author: @ScottWeinstein title: Reactive Extension 1.0 footer: @ScottWeinstein subfooter: Lab49 presdate: 7/16/2011

#LinqPad Demos

  1. [BackgroundThread](LinqPadSamples/01 BackgroundThread.linq)
  2. [ThreadSafe](LinqPadSamples/01 ThreadSafe.linq)
  3. [ColdEnumerable]("LinqPadSamples/02 ColdEnumerable.linq")
  4. [ColdObservable]("LinqPadSamples/03 ColdObservable.linq")
  5. [HotObservable]("LinqPadSamples/04 HotObservable.linq")
  6. [Create]("LinqPadSamples/06 Create.linq")
  7. [CreateDisposable]("LinqPadSamples/06 CreateDisposable.linq")
  8. [GenerateWithTime]("LinqPadSamples/07 GenerateWithTime.linq")

VisualStudio Demos

Querying a server

  1. A slow or expensive query
  2. On a background loop
  3. With user initiated action, for the impatient
  4. But not too often
  5. Compare the ad-hoc w/ the Rx approach

###UI for password check

  1. Accept correct password
  2. Reject incorrect
  3. No “submit button”
  4. Timeout
  5. Must be unit testable

Twitter client

  1. Need to make an IO from a traditional API
  2. Want a mock version for UI development
  3. Only want to show latest for each user
  4. Want late subscribers to have latest values

Streaming Olap

Agenda

  • What's the Rx thing about, why should I care?
  • Will it make my life easier?
  • What's new in 1.0

What's the Rx thing about, why should I care?

  • 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

Reactive matters

  • 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...

A good way?

  • Composable
  • Testable
  • Pure (side-effect free)

###Two use cases

  1. Managing a bar
  2. Calling a web service async

So what is Rx?

  • A new Interface pair IObservable<T> and IObserver<T> for .Net BCL
    • The dual of IEnumerable<T> and IEnumerator<T>
  • A core implementation and a set of Linq combinators for doing useful things

A look at some recent Rx questions

Open questions?

More Details - IEnumerable and IEnumerator

<% code :lang => 'csharp', :line_numbers => 'off' do %> interface IEnumerable� {� IEnumerator GetEnumerator();� }

interface IEnumerator: IDisposable � {� T Current { get; } � bool MoveNext();� } <% end %>

More Details - IObservable and IObserver

<% code :lang => 'csharp', :line_numbers => 'off' do %> interface IObservable� {� IDisposable Subscribe(IObserver observer);� }

interface IObserver� {� void OnCompleted();� void OnError(Exception error);� void OnNext(T value);� } <% end %>

Pop Quiz - Hot or Not?

JessRabbit

Pop Quiz - Hot or Not?

  1. new[] { 1, 2, 3, 4 }
  2. new List<string>()
  3. Enumerable.Range(1, Int32.MaxValue)
  4. new int[Int32.MaxValue]
  5. People.Where(pers => pers.Age >= 21)
  6. Observable.Range(1,3)
  7. Observable.FromEvent("Click")

Traps

  • Avoid implementing IObservable from scratch
  • Hot or not?

How to build

##Demos

You must first compile via command line msbuild.

> msbuild .\rx.msbuild

To run the twitter example, you'll need to create the authkeys.txt file and add your own twitter API authkey

Slide deck

slideshow -f http://github.com/geraldb/slideshow-s6-syntax-highlighter/raw/master/s6syntax.txt
slideshow -t s6syntax.txt .\README.md -o Slideshow

About

Reactive Extensions code demos