Skip to content
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

Switch Operator dispose order #300

Closed
ProffP opened this issue Feb 5, 2025 · 3 comments
Closed

Switch Operator dispose order #300

ProffP opened this issue Feb 5, 2025 · 3 comments

Comments

@ProffP
Copy link

ProffP commented Feb 5, 2025

The switch operator in R3 will observe the next inner observable before disposing the current.

This is inconsistent with the behaviour of ReactiveExtensions. So when migrating from ReactiveExtensions I had to define a new operator where the SerialDisposable was assigned Disposable.Empty prior to the new observation.

I’m not sure that this is a big issue as it’s easy to produce new operators, perhaps a Boolean can be passed to change the order or it’s something to note in the method description in some way.

@neuecc
Copy link
Member

neuecc commented Feb 5, 2025

Thank you for the detailed explanation.
I consider this to be an unintended incompatibility that needs to be fixed.
Please wait a moment, I will definitely fix it.

@ProffP
Copy link
Author

ProffP commented Feb 11, 2025

Great, thanks 👍

@ProffP
Copy link
Author

ProffP commented Feb 11, 2025

For reference, the code in ReactiveExtensions: https://github.com/dotnet/reactive/blob/main/Rx.NET/Source/src/System.Reactive/Linq/Observable/Switch.cs

It seems that there is an InnerObserver class that has a Resource set after assigning the SerialDisposable:

public override void OnNext(IObservable<TSource> value)
{
	ulong id;
	
	lock (_gate)
	{
		id = unchecked(++_latest);
		_hasLatest = true;
	}

	var innerObserver = new InnerObserver(this, id);

	_innerSerialDisposable.Disposable = innerObserver;
	innerObserver.SetResource(value.SubscribeSafe(innerObserver));
}

@neuecc neuecc closed this as completed in 2b53194 Feb 13, 2025
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

No branches or pull requests

2 participants