[Pitch #3] Async Let

I answered a bit too quickly here, let me revise my post a bit.

Right yeah this is a change after the 2nd review of the structured concurrency proposal indeed.
It didn't yet get a proper summary writeup but as Ben mentions, we are working on revisions based on the review:

You can already view all the changes for the 3rd review of structured concurrency over here: [Struct Concurrency] Update for 3rd review by ktoso · Pull Request #1345 · apple/swift-evolution · GitHub

--

So, why async?

The spawn word came up because of the analogy with "spawning threads" and it read quite nicely with group.spawn.

Sadly, it did not read well in other contexts. Most notably, spawn let was not a spelling we felt comfortable with, and the previous spelling of async let really looks much more awesome and was met with some enthusiasm in prior reviews.

Because of that, I and the other proposal authors (@Douglas_Gregor @John_McCall and @Joe_Groff ) would want to keep the async let spelling. We also introduce the new, and very important, async {} operation in the 3rd structured concurrency review ([Struct Concurrency] Update for 3rd review by ktoso · Pull Request #1345 · apple/swift-evolution · GitHub), which makes for an odd situation:

  • group.spawn - only the group uses the spawn word
  • async let
  • async {}
  • detach

Because we have a mix of different words to mean creating a task. Given that spawn is the odd one here, we decided that we can stick to using the word async consistently to mean creating a child task, this way we arrive at a consistent API in all contexts:

  • group.async { }
  • async let
  • async {}
  • and asyncDetached {}

We can say that "async creates async tasks" and that's always correct. Specifically, the group's async and async let create child async tasks. And the other APIs create async tasks which are not child tasks. Overall we feel this is a simple rule to follow, and does not introduce yet another new word into the swift concurrency vocabulary.

Hope this helps!

12 Likes