Skip to content

Commit

Permalink
ObserveOn
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Dec 26, 2023
1 parent 8b767b3 commit 8aed3fc
Show file tree
Hide file tree
Showing 4 changed files with 601 additions and 450 deletions.
10 changes: 9 additions & 1 deletion src/R3/Observable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ public abstract class Observer<T> : IDisposable
public bool IsDisposed => Volatile.Read(ref disposed) != 0;
bool IsCalledCompleted => Volatile.Read(ref calledOnCompleted) != 0;

// enable/disable auto dispose on completed.
protected virtual bool AutoDisposeOnCompleted => true;

[StackTraceHidden, DebuggerStepThrough]
public void OnNext(T value)
{
Expand Down Expand Up @@ -87,17 +90,22 @@ public void OnCompleted(Result result)
}
if (IsDisposed) return;

var disposeOnFinally = AutoDisposeOnCompleted;
try
{
OnCompletedCore(result);
}
catch (Exception ex)
{
disposeOnFinally = true;
ObservableSystem.GetUnhandledExceptionHandler().Invoke(ex);
}
finally
{
Dispose();
if (disposeOnFinally)
{
Dispose();
}
}
}

Expand Down
Loading

0 comments on commit 8aed3fc

Please sign in to comment.