Erik Meijer: Your Mouse is a Database - Rx and Modern Asynchronous Programming

PL icon Erik Meijer recently published an ACM article covering Reactive Extensions (aka Rx). As Erik notes in the article (emphasis mine) "the goal of Rx is to coordinate and orchestrate event-based and asynchronous computations such as low-latency sensor streams, Twitter and social media status updates, SMS messages, GPS coordinates, mouse moves and other UI events, Web sockets, and high-latency calls to Web services using standard object-oriented programming languages such as Java, C#, or Visual Basic."

His conclusion:

Web and mobile applications are increasingly composed of asynchronous and real-time streaming services and push notifications, a particular form of big data where the data has positive velocity. This article has shown how to expose asynchronous data streams as push-based collections of type IObservable (in contrast to pull-based collections of type IEnumerable) and how to query asynchronous data streams using the fluent API operators provided by the Rx library. This popular library is available for .NET and JavaScript (including bindings for prevalent frameworks such as jQuery and Node) and also ships in the ROM of Windows Phone. F#'s first-class events are based on Rx, and alternative implementations for other languages such as Dart7 or Haskell6 are created by the community.

What do you think of the Rx approach to asynchronous computation?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

The main problem I've always

The main problem I've always had with Rx has been that events, in practice, are not as composable as data streams (enumerables) are given their discrete time component. So Rx can shine for small examples, but in practice, at least for UI programming, it quickly becomes an added burden and it's just easier to build your own state machines on top of naked event handlers. The broken mouse-capture Silverlight samples were a perfect example of this problem; you just can't deal with mouse events like that in a real application! To fix, they'd have to side effect the event stream wrapper to capture the mouse for only the duration of event observation, but since mouse capture cuts across the entire UI hierarchy, this is difficult to automate. The analogous problem occurs with touch.

Yes, there is a nice duality between events and streams. However, the pragmatics are totally different, which is where I think Rx must be improved before it can become mainstream/popular.

The article seems to use big data/sensors as a teaser in its intro, but then does mostly UI examples; the reader is left to extrapolate. Actually, big data is much more of a problem of partitioning and topology, so I'm not sure how Rx really helps here. Also, sensors are often filtered through some kind of machine learning, and again, I'm not sure how event stream abstractions are helpful here, its not simple filtering via "Where."

Subject/Observer is dual to Iterator

That Subject/Observer is dual to Iterator does seem like a nice observation.