UniRx icon indicating copy to clipboard operation
UniRx copied to clipboard

ToReactiveProperty creates ReadOnlyReactiveProperty

Open MarcelUsslar opened this issue 5 years ago • 8 comments

image Currently using ToReactiveProperty will create a ReadOnlyReactiveProperty and only return its interface. Due to the interface not being an IDisposable the subscription to the stream (which is created inside the ReadOnlyReactiveProperty) can no longer be disposed. image

MarcelUsslar avatar Jun 11 '19 12:06 MarcelUsslar

Why this problem is not resolved for 4+ years? It makes very handy ToReactiveProperty a bad practice.

Hinidu avatar Nov 23 '23 15:11 Hinidu

Why this problem is not resolved for 4+ years? It makes very handy ToReactiveProperty a bad practice.

Because it's not a problem? If you need multiple sources of data merged together, use .Merge(...), multicast to Subject, or any other way of explicit definition of such thing. Manually pushing values in existing stream of data is asking for GMS-related issues, which is Rx solving in first place.

elhimp avatar Nov 25 '23 10:11 elhimp

@elhimp I don't understand how your comment relates to this issue at all.

  1. If this is not a problem, this issue should be closed by a maintainer explaining why this is not an issue.
  2. The issue is not about merging multiple sources of data, so your suggestions are pointless - after .Merge or any other combination of observable operators you still may want to create ReadOnlyReactiveProperty from it's result for whatever reason.
  3. Why are you talking about manually pushing values to existing stream of data? ReadOnlyReactiveProperty doesn't allow that because it is read only.

The issue is that ToReactiveProperty creates a subscription you can't dispose. I don't see how anybody can insist that API creating undisposable subscriptions is not an issue.

Hinidu avatar Nov 25 '23 11:11 Hinidu

@Hinidu I get your issue wrong. Sorry. Your issue is already solved. If you wanna create ReadOnlyReactiveProperty just use .ToReadOnlyReactiveProperty Not having more guard rails isn't an issue, unless you're not trying to cater for type of person who tries to dry their hair in microwave.

elhimp avatar Nov 27 '23 04:11 elhimp

I also encountered this issue, this is just a leak in every call to ToReactiveProperty Adding IDisposable to the interface compiles, I guess this is just a mistake. Still testing it before doing anything in the main repo public interface IReadOnlyReactiveProperty<T> : IObservable<T> -> public interface IReadOnlyReactiveProperty<T> : IObservable<T>, IDisposable

TheAnosmic avatar Feb 13 '24 13:02 TheAnosmic

这是来自QQ邮箱的假期自动回复邮件。   您好,我最近正在忙碌中,无法亲自回复您的邮件,之后将尽快给您回复。

qipa avatar Feb 13 '24 13:02 qipa

@elhimp I understand why you don't like adding IDisposable to a read only interface. I would also accept deleting ToReactiveProperty because there is no way to use it without leaking a subscription

TheAnosmic avatar Feb 13 '24 13:02 TheAnosmic

@elhimp I understand why you don't like adding IDisposable to a read only interface. I would also accept deleting ToReactiveProperty because there is no way to use it without leaking a subscription

Sure, that's more reasonable.

elhimp avatar Feb 13 '24 16:02 elhimp