Fix: AsObservable immediately calls Dispose on completion - #392
Closed
TORISOUP wants to merge 1 commit into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a completion-propagation bug when AsObservable() (and AsSystemObservable()) is used in operator chains that delay notifications, where OnCompleted could be lost due to premature disposal.
Changes:
- Update
AsObservable()to subscribe with a dedicated observer that does not auto-dispose on completion. - Update
AsSystemObservable()bridge observer behavior (and add a new regression test for delayed completion onAsObservable()). - Add a unit test covering
AsObservable()composed withDelayFrame(...)to ensure completion is delivered.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| tests/R3.Tests/OperatorTests/AsObservableTest.cs | Adds a regression test ensuring delayed completion is observed after AsObservable() + DelayFrame. |
| src/R3/Operators/AsObservable.cs | Changes AsObservable() to avoid premature disposal on completion; adjusts AsSystemObservable() observer behavior. |
Suppressed comments (1)
tests/R3.Tests/OperatorTests/AsObservableTest.cs:46
- PR description says a similar completion-propagation issue was fixed in
AsSystemObservable(), but the tests here only cover the basic (non-delayed)AsSystemObservablepath. Please add a regression test that composesAsSystemObservable()with a message-delaying System.Reactive operator (e.g.,Delay(TimeSpan.Zero)orObserveOn(...)) and assertsOnCompletedis eventually observed downstream.
[Fact]
public void AsSystemObservable()
{
{
var p = new Subject<int>();
var l = new List<int>();
Exception? ex = null;
bool completed = false;
p.AsSystemObservable().Subscribe(l.Add, e => ex = e, () => completed = true);
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
61
to
65
| sealed class ObserverToObserver(IObserver<T> observer) : Observer<T> | ||
| { | ||
| protected override bool AutoDisposeOnCompleted => false; | ||
|
|
||
| protected override void OnNextCore(T value) |
Contributor
Author
|
Closing this to explore a different approach. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resubmitting #331.
As pointed out in #330, when using
AsObservable()in combination with message-delaying operators such asDelayorObserveOn, the OnCompleted signal was not properly propagated downstream.The cause was that
WrappedObserveris defined withAutoDisposeOnCompleted = true, andAsObservable()uses it as-is.As a fix,
AsObservable()now uses a dedicated observer.A similar issue was also present in
AsSystemObservable(), so it has been fixed as well.