Pull Versus Push

The IObservable<T> and IObserver<T> interfaces might look a little weird at first, but they are actually very closely related to the well-known System.Collections.Generic interfaces IEnumerable<T> and IEnumerator<T>. In fact, they are mathematical duals. It’s normal you perceive this as rather abstract, but it’s rather simple. Follow me.

From our discussion about statements, recall that IEnumerable<T>’s primary use is the foreach loop statement. Collections implement this interface, allowing us to retrieve their data by pulling it out one by one. In fact, the consumer is in control, which makes this an interactive mechanism. To pull data from the source, the consumer asks the enumerator for more data by calling MoveNext and ...

Get C# 5.0 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.