Swift Concurrency: Feedback Wanted!

Explicitly cancelling tasks can be done if you create an unstructured task via Task{ call your actor here } and keeping that task handle around. You can call cancel() on it whenever you want. Do note that cancellation is co-operative, so your code would have to be checking and reactig to cancellation.

Custom executors is something we're thinking about, but are not shipping today, see here Support custom executors in Swift concurrency. That'd eventually address your question for more control over where exactly things execute. For now you can generally think of a single actor "as if" it had it's own mailbox queue (they don't, they share a global pool, but semantically it is "as if" they did.) So that's not quite a thing yet in Swift Concurrency.

You may also enjoy the Explore structured concurrency in Swift - WWDC21 - Videos - Apple Developer Explore structured concurrency in Swift talk which discusses a little bit about cancellation and tasks in general - which is at which level cancelation happens (not really at the actor level per se).

Depending on more specific examples maybe we can offer some advice though.

1 Like