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

Task (on MainActor) may be executed other than the main thread. #59742

Open
soranoba opened this issue Jun 28, 2022 · 1 comment
Open

Task (on MainActor) may be executed other than the main thread. #59742

soranoba opened this issue Jun 28, 2022 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@soranoba
Copy link

Describe the bug
Task (on MainActor) may be executed other than the main thread.

Task {
    do {
        // It should do anything on main thread.
    } catch {
        // It should do anything on main thread, but sometimes executed on other than the main thread.
    }
}

To Reproduce
All code is here on the branch in the repo.
https://github.com/soranoba/iOS-SandBox/tree/TaskMayBeExecutedOtherThanTheMainThread

    @IBAction private func didTapStoreKitCase(_ sender: UIButton) {
        Task {
            do {
                print("SK-1: isMainThread = \(Thread.isMainThread)")
                let vc = SKStoreProductViewController()
                _ = try await vc.loadProduct(withParameters: [SKStoreProductParameterProductIdentifier: "xxxxxx"])
            } catch {
                print("SK-2: isMainThread = \(Thread.isMainThread)")
            }
        }
    }

It should output:

SK-1: isMainThread = true
SK-2: isMainThread = false

Expected behavior

It should output:

SK-1: isMainThread = true
SK-2: isMainThread = true

Environment (please complete the following information):

  • OS: iOS 15.4
  • Xcode Xcode 13.3.1
@soranoba soranoba added the bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. label Jun 28, 2022
@soranoba
Copy link
Author

Reproduced 100% with SKStoreProductViewController.loadProduct (withParameters :), but never reproduced with other methods 🤔

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.
Projects
None yet
Development

No branches or pull requests

1 participant