I understand the basics of Rx. Where I'm struggling is how you would actually use this beyond academic examples? What are some common, simple real-world scenarios where Rx is a much better solution than what we have today in .NET?
-
3I wrote a demo of Bing search in WPF with Rx : http://blog.andrei.rinea.ro/2013/06/01/bing-it-on-reactive-extensions-story-code-and-slides/ – Andrei Rînea Jun 01 '13 at 20:48
-
2I answer exactly this question in a series of posts on my blog: http://rehansaeed.co.uk/reactive-extensions-part1-replacing-events/ – Muhammad Rehan Saeed Sep 24 '14 at 12:52
-
1Please have a look at https://github.com/AdaptiveConsulting/ReactiveTraderCloud. I think that is a good example because they used a lot of Reactive Extension for their sample. Cheers! – thangchung Dec 29 '16 at 12:01
6 Answers
For a bunch of good examples, see the 101 Rx Samples wiki

- 26,911
- 4
- 71
- 95
-
13Thanks for the link. There's some pretty good samples there. Still don't quite see that head slapper - "oh that's the canonical problem this solves" sample. Then again, could just be me being slow on the uptake. – Keith Hill Mar 31 '10 at 15:27
-
10Hem... despite its high score, this answer remains "link-only". Could you perhaps flesh it out a bit? – jub0bs Jan 05 '15 at 14:41
-
-
-
First of all, IObservable is an event. So in anywhere you use events internally, you can use IObservable - and if you later need to apply LINQ to this event, you're able to do it without refactoring.
Second, RX is fit for any situation when you need to run your code asynchronousely. For example, calling a web service, or loading a large image.
But when it really starts to shine - if your program reaches some "critical mass" of IObservable usage and you start combining different observables you would be amazed how easy some tasks become.

- 23,155
- 11
- 57
- 79

- 22,316
- 18
- 72
- 99
Rx allows you to write code that orchestrates concurrent events together. If you've ever used the TPL (i.e. Task), then had to do convoluted backflips to try to ContinueWith or WaitAll on the right things, Rx is for you.
For example, the workflow of "For each item in this array, call a web service, and when all of those requests come back, do something else. If any one of them fail, fail the whole thing".
Disclosure, Shameless plug ahead: The book that Jesse Liberty and I wrote about Rx was designed to solve exactly this question, "How do I use Rx in my day-to-day work?"; "What can I do with this?"

- 73,868
- 16
- 141
- 209
- Device measurments
- Data comming in over a message bus
In both cases now, the standard way to receive the data is via events, but if I want query syntax, or composition, then RX gives it to me where events don't.

- 18,890
- 14
- 78
- 115
Rx is very general so it has unlimited utility, just like IEnumerable/IEnumerator has unlimited utility. IE pulls values, IO pushes values.
Foreach is a concrete example of where IEnumerables come in handy, but that doesn't explain IEnumerable, or yield or anything. Same goes with Rx.
Being able to look at something from either a pull point of view, or a push point of view, and being able to control the direction or means, is very powerful, because now you can push and pull computations around at will, using LINQ query operators for "free", against an IO, because it's the mathematical dual of IE.

- 10,550
- 3
- 42
- 62
I've just had my first look at Rx, but one fun project I'll use it for is creating a Silverlight widget that displays activity in our ASP.NET MVC web app (which action methods were called, by which user, etc). It seems that Rx can help with a lot of things in this project, such as concurrency management and Throttling.

- 33,034
- 36
- 130
- 210