A good example of using reactive extensions

I understand the basics of Rx. Where I struggle is how you actually use it outside of academic examples? What are some common, simple real-world scenarios where Rx is a much better solution than what we have today in .NET?

+73
c # system.reactive
Mar 31 '10 at 5:47
source share
6 answers

For a bunch of good examples, see the 101 Rx Samples wiki

+34
Mar 31 '10 at 6:04
source share

Rx allows you to write code that co-organizes parallel events. If you have ever used TPL (i.e., Job), then you had to do minimized back-ups to try and continue, or with WaitAll for the right thing, Rx is for you.

For example, the workflow "For each element in this array, call the web service, and when all these requests return, do something else. If any of them fail, fail it all."

Disclosure, Shameless plug-in ahead: The book that Jesse Liberty and I wrote about Rx was designed to address this very question: "How to use Rx on your day? -Day work?"; "What can I do with this?"

+26
Nov 07 '11 at 2:18
source share

First of all, IObservable is an event . That way, anywhere you use events inside you can use IObservable - and if you later need to apply LINQ to this event, you can do it without refactoring.

Secondly, RX is suitable for any situation where you need to run your code asynchronously . For example, calling a web service or loading a large image.

But when it really starts to glow - if your program reaches some “critical mass” of using IObservable, and you start combining different observables, you will be amazed at how easy the tasks become.

+25
Apr 25 2018-10-25T00:
source share
  • Device measurements
  • Data flowing through the message bus

In both cases, the standard way to get data is through events, but if I want query syntax or composition, then RX provides it to me where there are no events.

+4
Apr 19 '10 at 18:44
source share

Rx is very general, so it has unlimited utility, just like IEnumerable / IEnumerator has unlimited utility. IE pulls values, IO produces values.

Foreach is a concrete example of where IEnumerables come in handy, but that doesn't explain IEnumerable, or profitability, or anything else. The same thing happens with Rx.

The ability to look at something from the point of view of pushing or pushing point of view and to be able to control the direction or means is very effective, because now you can push and pull out the calculations as desired, using LINQ query operators for "free", against IO, because it is a mathematical dual IE.

+2
May 2 '10 at 6:10
source share

I only have a first look at Rx, but one interesting project for which I will use it is to create a Silverlight widget that displays activity in our ASP.NET MVC web application (what actions were triggered by which the user, etc. .d). It seems that Rx can help with a lot of things in this project, such as concurrency management and Throttling.

0
Jun 07 2018-11-11T00:
source share



All Articles