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

Idea: make DisposeBag a noncopyable type in RxSwift 7 #2633

Closed
nikolaykasyanov opened this issue Oct 11, 2024 · 4 comments
Closed

Idea: make DisposeBag a noncopyable type in RxSwift 7 #2633

nikolaykasyanov opened this issue Oct 11, 2024 · 4 comments

Comments

@nikolaykasyanov
Copy link
Contributor

nikolaykasyanov commented Oct 11, 2024

As far as my experience goes, dispose bags are usually attached to a single object's lifetime and (are supposted to) deinit with it.

Making DisposeBag a noncopyable type enforce this 1:1 relation and will prevent potential misuses, like passing DisposeBag around and retaining it somewhere accidentally, at compile time.

The obvious downside is code churn associated with it, because:

  • all dispose bags will have to be var to be usable (unless all disposables are passed once on bag's creation)
  • .disposed(by: bag) calls will have to become .disposed(by: &bag)
    But the above seems acceptable for a major release.

I'd appreciate your opinions and use cases that I didn't mention that may become problematic with DisposeBag being noncopyable.

PoC: #2634.

@freak4pc
Copy link
Member

Hey there -

It's an interesting discussion which I've considered but indeed making them mutable and inout is a large change.
Worse than that, it will force us to support min Swift 5.9 - which might be fine for iOS, etc, but not fine for Unix/Linux etc.

The change doesn't seem valuable enough to me for its related costs. At least my personal opinion around this.

@nikolaykasyanov
Copy link
Contributor Author

nikolaykasyanov commented Oct 11, 2024

@freak4pc thanks for your feedback!

Btw, it looks like the mutability/inout argument can be avoided if the implementation is kept as it is in POC now, where a noncopyable struct uses a class instance under the hood. The reason I added mutating modifiers is to make it build against Xcode 15.4 (it wasn't liking func insert(_ disposables: [Disposable]) not being mutating). Requiring Xcode 16, however, will raise the required Swift version even further.

@freak4pc
Copy link
Member

Right, totally understand -
I think that if the value was extremely high it would be worth considering, but as-is, the value vs. "payment" isn't balanced enough, so don't think can happen.

LMK if you feel comfortable closing this for now.

@freak4pc freak4pc reopened this Oct 13, 2024
@nikolaykasyanov
Copy link
Contributor Author

@freak4pc fair enough, I'm fine closing it.

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