Here’s a really quick sample on how to get into the upcoming Rx Framework, aka the Reactive Framework. I’m using System.Linq.Observable as the source object to “observe”.
To get this to run, download this version of System.Reactive (re-jiggered for the non-Silverlight folks), create a console application and paste the code below in Main.
var cookiePieces = Observable.Range(1, 10);
cookiePieces.Subscribe(x => Console.WriteLine(
"{0}! {0} pieces of cookie!", x),
ex => Console.WriteLine("Never going to happen in this sample..."),
() => Console.WriteLine("Ah! Ah! Ah! Ah!"));
Console.ReadLine();
All we’re really doing here is a little pump that executes 5 cycles and exits. The Observable class implements the IObservable interface and gives us some structure to test again (like they do in the Silverlight bits that came out in the summer).
I’m exploring the framework more and more and working through several composition scenarios. I’m liking what Rx has to offer at this point, especially the bits that allow for the extension of Linq to events.
No comments:
Post a Comment