Rx – Reactive Extension (part 1)
What is the Reactive Framework Extension?
the Rx formalize the push based programming pattern.
it is dealing with event like collection, in manner that can be describe as the mirroring of IEnumerable<T>.
How does it mirror the IEnumerable<T>?
the Rx framework most fundamental interface are,
IObservable<T> which is mirroring IEnumerable<T>.
and IObserver<T> which is the mirroring IEnumerator<T>
actually we getting formalized pattern for push collection (collection that may be endless)
which can push data into our IObserver<T> instance.
on of the benefit of this formalization is that we can use Linq query upon that push collection.
we will discuss IObservable<T> and IObserver<T> in more details on the following post of this series.
Interactive Vs. Reactive (pull Vs. Push)
we will discuss Interactive (IEnumerable<T>) Vs. Reactive (IObservable<T>) paradigms
by using journal reading analogy.
let say that you do like to read several journals at your home each day.
before the reading part the journals should reach your home.
you do have 2 options (Interactive or Reactive approach):
- Interactive: going each day to the nearby store (or several stores in
case that the nearby store does not have all of your favorite journals), collect the journals,
wait on the payment queue, pay for it and return home for reading.
- Reactive: subscribe to journal delivery service which will send the journals to
your door front each day.
the Reactive model is more native for parallel computing
and it can save the collecting time:
- go to the store
- wait on the payment queue (in the software world waiting for blocking threads)
in the next pasts we will discuss more benefit, scenarios and techniques.
How to get started?
in order of start using the Rx you have to download the library from here (it is available both for framework 3.5 and 4.0).
then you have to add reference to System.Reactive