Why RX has the following grammar OnNext* (OnError|OnCompleted)
? instead of (OnNext|OnError)* OnCompleted
? This is quite clear from implementation perspective(also this has common semantics with IEnumerable
and yield
) but I guess differs from real life situation. In real life - producers generate mixed stream of data and exceptions (and exceptions doesn't break producer).
The question:
If I understood correctly the only possible solution is to make observable return complex data structure combined from initial data and produced exceptions(Observable.Timestamp()
and .TimeInterval()
has similar concept) or are there any other options?
At the moment I came to the following solution:
Inside observable producer I manually handle exeptions and just pass them to the following data structure which is the result of my observable
public class ValueOrException<T>
{
private readonly Exception ex;
private readonly T value;
public ValueOrException(T value, Exception ex)
{
this.value = value;
this.ex = ex;
}
public ValueOrException(T value)
{
this.value = value;
}
public T Value
{
get { return this.value; }
}
public Exception Ex
{
get { return this.ex; }
}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…