6

Does anyone know, in the new Swift async/await stuff, is there any difference between TaskGroup async and spawn, or are they pure synonyms? (If they are synonyms, I rather like spawn better. async looks like we're opening an async block, and that's not what we're doing at all.)

https://developer.apple.com/documentation/swift/taskgroup/3814850-async

https://developer.apple.com/documentation/swift/taskgroup/3814884-spawn

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I think, `async` might have got deprecated – aheze Jun 15 '21 at 04:32
  • @aheze Really? That would be cool. What I saw was that `add` got deprecated, though, so maybe you're thinking of that? – matt Jun 15 '21 at 04:42
  • @Rob Oh nooooze! I was really hoping this would go the other way. The `async` name is so wrong here. – matt Jun 16 '21 at 04:16

1 Answers1

5

SE-0304, tells us that spawn was renamed async as part of the second review:

  • TaskGroup.spawn and TaskGroup.spawnUnlessCancelled have been renamed to TaskGroup.async and TaskGroup.asyncUnlessCancelled which are to be their final names. This aligns the naming with the renamed async let as the word signifying creation of a child task.

The portion in italics has subsequently been removed and the third review has renamed it again:

  • renamed TaskGroup.async and TaskGroup.asyncUnlessCancelled to TaskGroup.addTask and TaskGroup.addTaskUnlessCancelled. The fundamental behavior here is that we're adding a task to the group. add by itself does not suffice, because we aren't adding a value (accessible via next()), we are adding a task whose value will be accessible via next(). It also parallels the use of Task { ... } to create top-level tasks.
Rob
  • 415,655
  • 72
  • 787
  • 1,044
  • 1
    I'll wait to see if this actually happens... There are some things in the second review that have not happened in the beta. But I presume they will. :( – matt Jun 16 '21 at 04:25
  • Well they changed free-standing `async` to `Task.init`, but they haven't done anything about TaskGroup `async`. I liked `spawn` or `add` a lot better.... – matt Jul 20 '21 at 02:27
  • As I'm sure you know, it’s now `addTask`. – Rob Aug 30 '21 at 21:46
  • Yeah, I think that's way better. – matt Aug 30 '21 at 23:27