-
Notifications
You must be signed in to change notification settings - Fork 769
Closed
Description
Consider the following code:
var xs = Observable.Create<Unit>(async o =>
{
await Task.Delay(10);
o.OnError(new Exception());
}).Replay().RefCount();
xs.Subscribe(x => Console.WriteLine(x));
xs.Subscribe(x => Console.WriteLine(x), ex => Console.WriteLine(ex.Message));
await xs.DefaultIfEmpty();
The sequence above doesn't throw any exceptions and never completes.
I made the following observations:
- Removing the first subscription enables error propagation - exception is thrown in
Subscribe
context (last line) - Removing
.Replay().RefCount()
enables error propagation - exception is thrown inSubscribe
context (last line) - Removing
await Task.Delay(10)
enables error propagation - exception is thrown inOnError
call (withinCreate
method). Surprisingly, switching twoSubscribe
methods makes exception thrown atSubscribe
context (last line).
That being said, I am asking whether the following issues are by design:
- Observable sequence in the above scenario never being completed
- The fact that exception is sometimes thrown inside
Create
method, and other times - atSubscribe
context.
If this is by design, what would you recommend as a workaround? How do I publish my sequences so that all of my clients (observers) can safely handle exceptions in this case? Current behavior seems so arbitrary, especially for library writers. It also makes debugging very painful. Please advise.