Chapter 14. Data streams and the Reactive Extensions
This chapter covers
- Using IObservable to represent data streams
- Creating, transforming, and combining IObservables
- Knowing when you should use IObservable
In chapter 13, you gained a good understanding of asynchronous values—values that are received at some point in the future. What about a series of asynchronous values? For example, say you have an event-sourced system like the one in chapter 10; how can you model the stream of events that are produced and define downstream processing of those events? For example, say you want to recompute an account’s balance with every transaction, and send a notification if it becomes negative?
The IObservable interface provides an abstraction to represent such event streams. And not just event streams, but more generally data streams, where the values in the stream could be, say, stock quotes, byte chunks being read from a file, successive states of an entity, and so on. Really, anything that constitutes a sequence of logically related values in time can be thought of as a data stream.
In this chapter, you’ll learn what IObservables are, and how to use the Reactive Extensions (Rx) to create, transform, and combine IObservables. We’ll also discuss what sort of scenarios benefit from using IObservable.