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

drive's onNext closure should be main actor isolated #2586

Open
9 of 18 tasks
BrentMifsud opened this issue Mar 25, 2024 · 1 comment
Open
9 of 18 tasks

drive's onNext closure should be main actor isolated #2586

BrentMifsud opened this issue Mar 25, 2024 · 1 comment

Comments

@BrentMifsud
Copy link

BrentMifsud commented Mar 25, 2024

Short description of the issue:

With Swift 6 beta coming in June, and its full release in the fall, RxSwift should start offering better compliance with the new Swift 6 compiler changes.

One area of note here are Drivers. Which are supposed to guarantee main thread operation.

I propose that the method signature for drive be updated to take a main actor closure.

Expected outcome:

When using a driver, I should be able to read/write main actor isolated state.

What actually happens:

Call to main actor-isolated instance method 'myMainActorProperty' in a synchronous nonisolated context

Self contained code example that reproduces the issue:

class MyClass {

    @MainActor private var mutableState: String
    private var disposeBag = DisposeBag

    func updateMutableStateWithDriver(to newValue: String) {
        Observable.just(newValue)
            .asDriver(onErrorJustReturn: "Failed")
            .drive(with: self) { this, newValue in
                this.mutableState = newValue // Call to main actor-isolated instance method 'mutableState' in a synchronous nonisolated context
            }
            .disposed(by: disposeBag)
    }
}

RxSwift/RxCocoa/RxBlocking/RxTest version/commit

6.6.0

Platform/Environment

  • iOS
  • macOS
  • tvOS
  • watchOS
  • playgrounds

How easy is to reproduce? (chances of successful reproduce after running the self contained code)

  • easy, 100% repro
  • sometimes, 10%-100%
  • hard, 2% - 10%
  • extremely hard, %0 - 2%

Xcode version:

  15.3

⚠️ Fields below are optional for general issues or in case those questions aren't related to your issue, but filling them out will increase the chances of getting your issue resolved. ⚠️

Installation method:

  • CocoaPods
  • Carthage
  • Git submodules
  • Swift Package Manager

I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)

  • yes (which ones)
  • no

Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)

  • just starting
  • I have a small code base
  • I have a significant code base
@freak4pc
Copy link
Member

Hey there, thanks for the report!
I'm planning and hopeful to have some time to do a sweep with Complete Concurrency Checking to prepare for Swift 6.0. Happy to take any PRs around this if anyone's interested in tackling!

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