8

I'm thinking about bringing in Rx to my workplace but the more I learn about it the more I think it doesn't really give you an advantage.

We have a lot of server apps that take input data at one end and output it at the other end. Which is perfect for the actor model and "infinite" threading scalability, till now I've used ConcurrentQueues to implement message passing and I thought that Rx might be a good more functional alternative that can make concurrency more implicit that helps me move some of the data flow decisions from imperative code to the declarations of observables.

But reading about it and trying it I don't see much advantage over using regular old threads with ConcurrentQueues for message passing. What advantages does Rx give me? It is always said that even though .NET 4.5 made a lot of Rx obsolete (though async and Dataflow) it's still good for handling event streams. What cases present event streams and how do I identify them?

Ziv
  • 2,755
  • 5
  • 30
  • 42
  • You might find Netflix's use of Rx woth looking at, it seems to have worked well for them https://blogs.msdn.com/b/interoperability/archive/2013/02/05/netflix-solving-big-problems-with-reactive-extensions-rx.aspx – Wilka Apr 10 '13 at 09:37
  • As a (very rough) rule of thumb, if you are dealing with single values, use the TPL/Task api; if you are dealing with sequences of "events" (generic "something", not just .net events), use rx. Dataflow I'm less familiar with, I'd have to think about that. – JerKimball Apr 10 '13 at 13:43

2 Answers2

5

If you need to parallelize some tasks, use TPL.

If you need to perform asynchronous operations, use Task & async/await.

If you need to receive, filter and combine streams of events, use Rx. Note that Rx is not necessarily asynchronous - it is simply a model for dealing with event streams in the same way that LINQ is a model for dealing with collections.

Your use case sounds like the first option.

Alex
  • 7,639
  • 3
  • 45
  • 58
1

There's lots of similar questions on SO....

Rx is all about mathematically-based composition of asynchronous operations. TPL and "regular old threads" are non-compositional. You must see non-trivial examples before you can see where the composition really benefits you.

Take a look at this page of Intro to Rx (and the rest of it), and I am sure you'll begin to grok the reasons for Rx: http://introtorx.com/Content/v1.0.10621.0/01_WhyRx.html#WhyRx

Richard Anthony Hein
  • 10,550
  • 3
  • 42
  • 62