Introduction to Rx - PowerPoint PPT Presentation

Introduction to rx
1 / 26

  • Uploaded on
  • Presentation posted in: General

Introduction to Rx. Reactive Extension to .NET. What is Rx?. Observer pattern implementation. Hollywood principle Allows you to provide delegates to be called by another object. Favours Functional over OO. Plenty of extension methods Encourages monadic programming. Multiple targets.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

Download Presentation

Introduction to Rx

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript

Introduction to rx

Introduction to Rx

Reactive Extension to .NET

What is rx

What is Rx?

Observer pattern implementation

Observer pattern implementation

Hollywood principle

Allows you to provide delegates to be called by another object

Favours functional over oo

Favours Functional over OO

Plenty of extension methods

Encourages monadic programming

Multiple targets

Multiple targets

.NET 3.5

.NET 4.0

Silverlight 3

Silverlight 4

Windows Phone


Linq benefits

Linq benefits







Why rx

Why Rx?

Why would you use Rx and why do you care?

Asynchronous data

Asynchronous Data

Data being pushed

Async requests

Responsive ui

Responsive UI

WPF or Silverlight GUIs


Composition of streams of data

Composition of streams of data

  • Concatenation

    • Concat, OnError/Catch, Retry

  • Merging streams

    • Merge, Zip, SelectMany, Amb, CombineLatest, ForkJoin

  • Grouping stream data

    • GroupBy, Window, Buffer, GroupJoin

So what observer pattern is old news what? Observer pattern is old news

Observer pattern is ~15years old

Java has already got the interface

.NET has events

Introduction to rx


The Java interface is bloated

.NET events are pretty silly.

Core bits of rx

Core bits of Rx

Core bits of rx1

Core bits of Rx



ISubject<T1, T2>

Factory Methods

Extension Methods

Scheduling and Concurrency

Iobserver t


namespace System


public interface IObserver<in T>


void OnNext(T value);

void OnError(Exception error); void OnCompleted();



Iobservable t


namespace System


public interface IObservable<out T>



IObserver<T> observer);







public interface ISubject<in T1, out T2> 

: IObserver<T1>,

IObservable<T2>{  }

public interface ISubject<T> 

: ISubject<T, T>, 


IObservable<T>{ }


Factory methods

Factory Methods

Generate / GenerateWithTime

Range / Interval

Create / CreateWithDisposable

Empty / Return / Never / Throw

FromAsyncPattern / FromEvent

Extension methods

Extension Methods

  • Aggregates

    • Aggregate, Sum, Count, Max, Min, First, Last...

  • Filter

    • Where, Skip, Take, First, Last

  • Grouping

    • Window, Buffer, GroupJoin

  • Composition

    • Concat, Merge,

  • Flow control

    • Amb, Case, If, While

Scheduling and concurrency

Scheduling and Concurrency



public interface IScheduler


DateTimeOffset Now { get; }

IDisposableSchedule(Action action);


Action action,




Scheduler implementations

Scheduler implementations

namespace System.Concurrency


public static class Scheduler


public static ImmediateScheduler Immediate;

public static CurrentThreadSchedulerCurrentThread;

public static ThreadPoolSchedulerThreadPool;

public static NewThreadSchedulerNewThread;

public static TaskPoolSchedulerTaskPool;

public static DispatcherScheduler Dispatcher;






Who would benefit

Who would benefit?

  • WPF/Silverlight developers

    • Allowing Rx to schedule work on to the ThreadPool/TaskPool

    • Return results on the dispatcher

    • Easily testable (without pushing a Dispatcher frame!)

  • Serverside teams working on streaming data (finance, instrumentation)

    • Compose many feeds

    • Easily testable

    • IQbservable may allow you to send the declaration to the server to process (GPUs/FSharp expressions)

Code time

Code time

Best practices

Best Practices

Use marble diagrams (esp first 12 months)

Honour the Completion contracts

Apply scheduling only at the end consumer

Avoid breaking the monad (.First() etc)

Avoid Side effects (or be explicit via .Do())

Favour composition over creating new operators

Avoid use of Subjects, favour factories.

Google “Rx Design Guidelines”

Thanks to

Thanks to...

Mitch Wheat

Erik Meijer’s team at Microsoft


More content

More content

Data Developer Center(for the download or get via Nuget) (or just talk to James)

Rx Forums (which is the same as talking to James)

  • Login