This blog has, IMO, some great resources. Unfortunately, some of those resources are becoming less relevant. I'm still blogging, learning tech and helping others...please find me at my new home on http://www.jameschambers.com/.

Friday, November 13, 2009

Reactive Framework –> Hello World

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”.

image 



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