In learning about Rx I've come across an often repeated rule about Observables that is spelled out in The Observable Contract.
Upon issuing an OnCompleted or OnError notification, it may not thereafter issue any further notifications.
This makes good sense to me, since it would be confusing to have an Observable continue to produce values after it has completed, but when I tested the Observable.Range method in .NET I noticed that it does not exhibit that behavior, and in fact many Observables violate this rule.
var rangeObservable = Observable.Range(0, 5);
rangeObservable.Subscribe(Console.WriteLine, () => Console.WriteLine("Done first!"));
Console.ReadLine();
rangeObservable.Subscribe(Console.WriteLine, () => Console.WriteLine("Done second!"));
Console.ReadLine();
//Output:
//0
//1
//2
//3
//4
//Done first!
//0
//1
//2
//3
//4
//Done second!
Clearly rangeObservable
has called OnComplete
two times and produced values after the first OnComplete
. This leads me to believe that this is not a rule about Observables but instead a rule about Subscriptions. That is, an Observable may produce as many terminating messages as it wants, and even produce values after it has, so long as each Subscription only receives one terminating message and receives no further messages after that.
Do they actually mean Subscription when it says Observable? Are they truly different things? Do I have a fundamental misunderstanding of the model?