neuecc / UniRx

Reactive Extensions for Unity
MIT License
7.08k stars 892 forks source link

Why Subject->OnError stops it? #478

Open TimGameDev opened 3 years ago

TimGameDev commented 3 years ago

Hello,

Thanks for your implementation of Rx for Unity. Could you please describe why does calling of Subject->OnError stops it (stops the stream)? I'm asking because the Microsoft implementation of Rx, as far as I understand, doesn't contain such behaviour. Please take a look at the source code: https://github.com/dotnet/reactive/blob/main/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs#L93 and your implementation: https://github.com/neuecc/UniRx/blob/master/Assets/Plugins/UniRx/Scripts/Subjects/Subject.cs#L41

I appreciate your time.

Tim

Fijo commented 2 years ago

No they both behave the same regarding that. All ReactiveX implementations have it so that an error is an terminal state on an observable. If you don't want that you have to catch the error before it propagates further than you are ok with it stopping your streams.

I think Interlocked.CompareExchange(ref _observers, Terminated, observers) == observers is responsible for doing this in Rx.NET.