When would one choose to use Rx over TPL or are the 2 frameworks orthogonal?
From what I understand Rx is primarily intended to provide an abstraction over events and allow composition but it also allows for providing an abstraction over async operations. using the Createxx overloads and the Fromxxx overloads and cancellation via disposing the IDisposable returned.
TPL also provides an abstraction for operations via Task and cancellation abilities.
My dilemma is when to use which and for what scenarios?
The main purpose of Rx is not to provide an abstraction over events. This is just one of its outcomes. Its primary purpose is to provide a composable push model for collections.
The reactive framework (Rx) is based on IObservable<T>
being the mathematical dual of IEnumerable<T>
. So rather than "pull" items from a collection using IEnumerable<T>
we can have objects "pushed" to us via IObservable<T>
.
Of course, when we actually go looking for observable sources things like events & async operations are excellent candidates.
The reactive framework naturally requires a multi-threaded model to be able to watch the sources of observable data and to manage queries and subscriptions. Rx actually makes heavy use of the TPL to do this.
So if you use Rx you are implicitly using the TPL.
You would use the TPL directly if you wish direct control over your tasks.
But if you have sources of data that you wish to observe and perform queries against then I thoroughly recommend the reactive framework.