R3 icon indicating copy to clipboard operation
R3 copied to clipboard

Fix: AsObservable immediately calls Dispose on completion

Open TORISOUP opened this issue 8 months ago • 2 comments

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.

TORISOUP avatar May 01 '25 13:05 TORISOUP

This PR is stale because it has been open 180 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Oct 29 '25 00:10 github-actions[bot]

Please keep it open.

TORISOUP avatar Oct 29 '25 05:10 TORISOUP