NET Reactive Framework

From JVMLangSummit
Revision as of 15:28, 17 September 2009 by Jrose (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

.NET Reactive Framework

Erik Meijer, Microsoft

Project
Blog
Slides
File:Meijer Rx.pdf

Abstract

The .NET Reactive Framework — Erik Meijer

The .NET Reactive Framework (Rx) is an abstraction of the well-known Subject/Observer pattern derived as the mathematical dual of the iterator pattern.

We show how Rx can be used to program against event streams and asynchronous computations using LINQ syntax as well as using good old imperative code.

Types

(roughly translated to roughly-Java syntax)

Enumerable

interface Enumerable<T> {
  Enumerator<T> getEnumerator();
}

interface Enumerator<T throws E> extends Disposable {
  bool moveNext();
  T current() throws E;
}

Observable

interface Observable<T> {
  // dual to getEnumerator:
  Disposable putObserver(Observer<? extends T> o);
}

// dual to Enumerator, except that Disposable is not dualized:
interface Observer<T throws E> extends Disposable {
  // dual to moveNext returning false:
  void onCompleted();
  // dual to current() returning x:
  void onNext(T x) ;
  // dual to current() throwing e:
  void onError(E e) ;
}

Subject

interface Subject<S,T> extends Observer<S>, Observable<T> {
  // observes values of type S, produces values of type T
}

Related Work

  • F# first-class events
  • F# async workflows
  • Thomas P. Reactive LINKQ (in F#)
  • Esterelle, Lustre, ...
  • Functional Reactive Programming (has continuous time)
  • Unix pipes, PowerShell, SSIS, WWF (push-based data flow
  • Promises are like Subjects, with single event produced

With Promises, the language does lifting, e.g.: ps: Promise[String] => ps.length: Promise[int]
LINQ does not lift, is explicit: from ps ... select ps.length ...

Current Status

Future

Key Issues for Discussion

(please expand cooperatively)