18 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

If you’ve ever been to a financial hub like Wall Street or Canary Wharf, you’ve probably seen a ticker board, a luminous board displaying the latest price at which the most widely traded stocks are being traded. This is a good representation of a data stream: a stream of related values that are delivered through time.

Traders (both human and algorithms) keep an eye on the prices so that they can react to price changes: if a stock’s price rises or falls to a given level, they may decide to buy or sell, according to their investment strategy. This is, in essence, how reactive programming works: you define and consume data streams, potentially transforming the data in the streams in interesting ways, and define how your program should react to the data it consumes.

For example, if you have an Internet of Things in your home, you may have sensors that broadcast certain parameters (like room brightness or temperatures) and devices that react to changes in those parameters (regulating the window shutters or the air conditioning).

18.1 Representing data streams with IObservable

18.1.1 A sequence of values in time

18.1.2 Subscribing to an IObservable

18.2 Creating IObservables

18.2.1 Creating a timer

18.2.2 Using Subject to tell an IObservable when it should signal

18.2.3 Creating IObservables from callback-based subscriptions

18.2.4 Creating IObservables from simpler structures

18.3 Transforming and combining data streams

18.3.1 Stream transformations

18.3.2 Combining and partitioning streams

18.3.3 Error handling with IObservable

18.3.4 Putting it all together