[Pitch #3] Async Let

I don't understand what you mean by this last sentence.

Yes. An actor-isolated function will run its synchronous portions in the actor's execution context. Now, we retain the right to optimize away the "hop" over to the actor's execution context if we can prove that the actor is unused within the synchronous portion, i.e., there's no references to "self".

This is fine. It's a concurrent task, but it'll end up serializing on the same actor until (e.g.) it ends up suspending while waiting for data to come across the network. This is a good description:

Yes, that's right.

Yes, you can call asynchronous actor functions from inside the actor. You'll still need to await them, of course, because they could suspend in their execution.

We can look to clarify the wording. The initializer of an async let is not isolated to the actor, but like any code outside the actor, it can interact asynchronously with the actor---it just needs to await its turn.

One could imagine having async parameters of some sort, and allowing async let to be passed down to those:

func f(x: async Int) async { ... }

func g() async {
  async let y = doSomething()
  f(x: y)
}

The restrictions would have to be similar to inout, where we don't allow captures in non-escaping closures. It would be a lot of implementation work to make this happen, but I think it does fit.

Doug

1 Like