Introduction
As we have already learned, there are several approaches to create asynchronous programs in .NET and C#. One of them is event-based asynchronous pattern, which was already mentioned in the previous chapters. The initial goal of introducing events was to simplify implementation of the Observer
design pattern. This pattern is common for implementing notifications between objects.
When we discussed the Task Parallel Library, we noticed that the event's main shortcoming is their inability to be effectively composed with each other. The other drawback is that the Event-based Asynchronous Pattern is not supposed to be used to deal with the sequence of notifications. Imagine that we have IEnumerable<string>
that gives us string values. However, when we iterate over it, we do not know how much time one iteration will take. It could be slow, and if we use the regular foreach
or other synchronous iteration constructs, we will block our thread until we have the next value. This situation...