Let's assume we had this observable sequence (RX) and matching subscription:
var behaviorSubject = new BehaviorSubject<int>(3);
var sequence = behaviorSubject.Select(x => this.webservice.Call(x)).Switch();
var subscription = this.sequence.Subscribe(this.Subject.OnNext, this.OnSequenceFaulted);
The sequence is meant to do a webservice call each time the behaviorSubject
emits a new value, while cancelling previous requests. If an exception occurs during the webservice call, the subscription will be terminated (after calling the OnSequenceFaulted
method).
Is it a good practice to implement the OnSequenceFaulted
method like this? Do we need to restart (reassign) the sequence
as well as the subscription, given that the exception originated from the observable within the sequence
? And does a faulted subscription need to be explicitly disposed?
public void OnSequenceFaulted(Exception e)
{
subscription?.Dispose();
subscription = sequence.Subscribe(this.Subject.OnNext, this.OnSequenceFaulted);
}