Skip to content

Fix: AsObservable immediately calls Dispose on completion #331

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

TORISOUP
Copy link
Contributor

@TORISOUP TORISOUP commented May 1, 2025

As pointed out in #330, when using AsObservable() in combination with message-delaying operators such as Delay or ObserveOn, the OnCompleted signal was not properly propagated downstream.

var subject = new Subject<Unit>();
var fakeFrameProvider = new FakeFrameProvider();

subject
    .AsObservable()
    .ObserveOn(fakeFrameProvider)
    .Subscribe(
        onNext: _ => Console.WriteLine("Next"),
        onCompleted: _ => Console.WriteLine("Completed")
    );

subject.OnNext(Unit.Default);
fakeFrameProvider.Advance();
subject.OnCompleted();
fakeFrameProvider.Advance();

// "Completed" is not printed

The cause was that WrappedObserver is defined with AutoDisposeOnCompleted = true, and AsObservable() 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant