Understanding How IObservable Handles OnCompleted and OnError

Let's examine one critical aspect of the contract offered by IObservable: Once an observable sequence terminates with OnCompleted or OnError, no more items can be produced.

This raises the question: how do you get work done if OnCompleted or OnError interrupt the flow with such finality? This section will examine this dilemma and the solution.

The finality of OnCompleted is illustrated in the following example, which schedules a number of values to be observed, but interrupts with OnCompleted after the second value:

var sched = new TestScheduler(); var input = sched.CreateColdObservable(         sched.OnNextAt(200, 1),         sched.OnNextAt(300, 10),         sched.OnCompletedAt<int>(350.0), ...

Get Programming Reactive Extensions and LINQ now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.