Skip to content

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

Open
@ktoso

Description

@ktoso

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions