Introduction to rx
Download
1 / 26

Introduction to Rx - PowerPoint PPT Presentation


  • 153 Views
  • Uploaded on

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.

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

PowerPoint Slideshow about ' Introduction to Rx' - ezekiel-larson


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



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

JavaScript!


Linq benefits
Linq benefits

Composable

Transformative

Declarative

Extensible

Unitive

Integrated


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

AJAX


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
...so what? Observer pattern is old news

Observer pattern is ~15years old

Java has already got the interface

.NET has events


But...

The Java interface is bloated

.NET events are pretty silly.



Core bits of rx1
Core bits of Rx

IObserver<T>

IObservable<T>

ISubject<T1, T2>

Factory Methods

Extension Methods

Scheduling and Concurrency


Iobserver t
IObserver<T>

namespace System

{

public interface IObserver<in T>

{

void OnNext(T value);

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

}

}


Iobservable t
IObservable<T>

namespace System

{

public interface IObservable<out T>

{

IDisposableSubscribe(

IObserver<T> observer);

}

}


Subjects
Subjects

namespaceSystem.Collections.Generic

{

public interface ISubject<in T1, out T2> 

: IObserver<T1>,

IObservable<T2>{  }

public interface ISubject<T> 

: ISubject<T, T>, 

IObserver<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

namespaceSystem.Concurrency

{

public interface IScheduler

{

DateTimeOffset Now { get; }

IDisposableSchedule(Action action);

IDisposableSchedule(

Action action,

TimeSpandueTime);

}

}


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;

}

}

//EventLoopScheduler

//TestScheduler

//ControlScheduler


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)



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

Lab49


More content
More content

Data Developer Center(for the download or get via Nuget)

LeeCampbell.blogspot.com

EnumerateThis.com (or just talk to James)

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


ad