The .NET Reactive Framework (Rx) uses Linq to build asynchronous code declaratively. It will be part of .NET 4.0. As of today the only place you can get it is in the Silverlight Toolkit sources (System.Reactive.dll in the bin folder of the Silverlight Toolkit Unit Tests). The Silverlight Toolkit team is using Rx to write reliable, event-based asynchronous tests.
Jafar Husain, a developer on the Presentation Platform Controls team at Microsoft, has written very interesting posts about Rx Framework with many practical examples:
- http://themechanicalbride.blogspot.com/2009/04/rx-framework-asynchronous-programming.html
- http://themechanicalbride.blogspot.com/2009/07/introducing-rx-linq-to-events.html
- http://themechanicalbride.blogspot.com/2009/07/developing-with-rx-part-1-extension.html
- http://themechanicalbride.blogspot.com/2009/07/developing-with-rx-part-2-converting.html
- http://themechanicalbride.blogspot.com/2009/08/joy-of-rx-building-asynchronous-service.html
Erik Meijer has discovered that IEnumerable has a dual characteristic: as one can pull a piece of data from a collection, he can also push one into the same collection. So the Observable pattern and the Iterator pattern are the same pattern !!! But IEnumerable can’t be used in asynchronous operations because it blocks and the team has introduced a new pair of interfaces: IObservable and IObserver.
Rx allows you to write complex, asynchronous code declaratively. With Linq to IObservable you can transform and combine events and async callbacks to create the precise event you’re interested in. Then you register a handler and do something with the data. Rx enables you build complex events from a sequence of primitive events (f.e click, drag & drop) !
The framework includes lots of methods for constructing observables and observers. Converting events to IObservables is very easy. Rx provides a static Observable.FromEvent method. It's good practice to create extension methods for each event you would like to query (extension events).
No comments:
Post a Comment