SE-0306 (Second Review): Actors

You're very right that this is a crucial piece and quite necessary sometimes.

The proposals so far have been avoiding this topic so you're right that there is no good API to achieve this in the existing proposals.

There is work in progress and to be pitched work which will address this over here though: https://github.com/apple/swift/pull/37007 (will get it's own evolution thread, let's not hyper focus on it just yet please :pray:)

While it is aimed to solve the "call async from sync" it also solves the issue of "send without waiting" (and I'd honestly lobby to call this operation send, but let's chat once it gets it's SE review).

With that proposal, the closure is run on the same executor as the enclosing context; so if used from an actor, the enclosing context is the actor's serial executor, this means that:

async (or send) { 
  await worker.hello(1)
} // -> Void
async (or send) { 
  await worker.hello(2)
} // -> Void

would do the right thing here.

It is very important to not devolve into using detach for such things, because a detach would lose: priority, executor, and also any task-locals attached to the calling task that you'd most definitely want to keep propagating.


I have yet to figure out if and how to solve "no need to even send back the result" in the distributed actor setting... but we'll figure that out and I'm pretty sure it could fit the above async (or send) API.

2 Likes