From iterators to observables
The iterator pattern is the standard mechanism to pull data from STL containers, generators, and streams. They are well-suited for data that has been aggregated in the space. Essentially, this means that we know ahead of time how much data is supposed to be retrieved, or that the data has already been captured. There are scenarios where the data arrives asynchronously and the consumers are not aware of how much data there is or when the data arrives. In such cases, iterators need to wait, or we need to resort to timeout strategies to handle the scenarios. In such a scenario, a push-based approach seems to be a better option. Using the subject construct of Rx, we can use a fire-and-forget strategy. Let's write a class that emits the contents of a directory, as shown here:
////////////////////////////// // A Toy implementation of Active // Object Pattern... template <class T> struct ActiveObject { rxcpp::subjects::subject<T> subj; //...