Skip to content

Commit

Permalink
Add Subject.Dispose(bool callOnCompleted)
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Aug 19, 2024
1 parent ae91aab commit 5eb7024
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/R3/Subject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,30 @@ void ThrowIfDisposed()
}

public void Dispose()
{
Dispose(true);
}

public void Dispose(bool callOnCompleted)
{
if (completeState.TrySetDisposed(out var alreadyCompleted))
{
if (!alreadyCompleted)
if (!alreadyCompleted && callOnCompleted)
{
var currentVersion = GetVersion();
var node = root;
Volatile.Write(ref root, null);
while (node != null)
{
if (node.Version > currentVersion) break;
node.Observer.OnCompleted();
node = node.Next;
}
}
else
{
Volatile.Write(ref root, null);
}
}
}

Expand Down

0 comments on commit 5eb7024

Please sign in to comment.