Thank you! This looks mostly really good, just a few questions:
An asynchronous function that is currently running always knows the executor that it's running on.
What's the API to query the current executor? Or if there's no API to query it, what does it mean for the function to "know" its executor?
Swift provides a default executor implementation, but both actor classes and global actors (described in separate proposals) can suppress this and provide their own implementation.
How can non-actor classes provide a custom executor? And what API/magic registration/... do custom executors need to implement?
extension Task {
/// Describes the priority of a task.
enum Priority: Int, Comparable {
/// The task is important for user interaction, such as animations, event handling, or
/// updating your app's user interface
case userInteractive
/// The task was initiated by the user and prevents the user from actively using
/// your app.
case userInitiated
/// Default priority for tasks.
case `default`
/// Priority for a utility function that the user does not track actively.
case utility
/// Priority for maintenance or cleanup tasks.
case background
I do understand that at this moment in time, the majority of Swift code written are indeed apps for Apple platforms which is probably why you're proposing to hard-code the priority names to make sense in a system where a user interacts with a UI. But IMHO Swift should be a general purpose language and I don't think we should hardcode the priorities to have a "UI meaning". Why not just highest, high, default, low, lowest and map the proposed spellings to that (userInteractive -> highest, ..., background -> lowest).
And finally, (this is actually a quote from the async/await proposal):
However, many asynchronous functions are not just asynchronous: they’re also associated with specific actors (which are the subject of a separate proposal), and they’re always supposed to run as part of that actor. Swift does guarantee that such functions will in fact return to their actor to finish executing.
What mechanism is used for this hopping-back to a certain actor, can this also be used with custom executors?