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

Document FIFO (or lack thereof) guarantees when coming from Dispatch #22

Open
ktoso opened this issue May 31, 2024 · 1 comment · May be fixed by #69
Open

Document FIFO (or lack thereof) guarantees when coming from Dispatch #22

ktoso opened this issue May 31, 2024 · 1 comment · May be fixed by #69

Comments

@ktoso
Copy link
Member

ktoso commented May 31, 2024

Hi there Matt,
I'll help out with some of the more gnarly runtime topics of the guide.
I think we can have a guide about "coming from dispatch" and surprising behaviors etc.

One thing I wanted to note down for me to get back to is:

People write this code:

  DispatchQueue.main.async(qos: .utility) { }
  DispatchQueue.main.async(qos: .background) { }

and the equivalent with main actor:

@globalActor actor TestActor {
    static let shared = TestActor()

    @MainActor
    func performOnMainActor() async {
        Task(priority: .low) { @MainActor in
            print("first")
        }
        Task(priority: .high) { @MainActor in
            print("second")
        }
    }

    @TestActor
    func performOnTestActor() async {
        Task(priority: .low) { @TestActor in
            print("first")
        }
        Task(priority: .high) { @TestActor in
            print("second")
        }
    }
}

So Task {} Task{} cannot be blindly assumed to be FIFO in face of priority escalation, without knowing the exact target actor's executor.

We need to properly document what users may expect and what not.


I'll write a portion to the guide about this.

@mattmassicotte
Copy link
Collaborator

Hello!

I completely agree this is an important to cover, and I'm really excited about this. I struggled tremendously at first with these exact kinds of things.

However, just a data point. I never used made use of qos in my own code. I had problems with just plain-only Task {} as I transitioned from sync -> async. I think that SE-0431 may help a lot here, especially in the simpler cases.

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

Successfully merging a pull request may close this issue.

2 participants