任务组“async”与“spawn”

TaskGroup `async` vs. `spawn`

有谁知道,在新的Swift async/await 东西中,TaskGroup asyncspawn 之间有什么区别吗?或者它们是纯粹的同义词? (如果它们是同义词,我更喜欢 spawnasync 看起来我们正在打开一个 async 块,而这根本不是我们正在做的。)

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

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

SE-0304,告诉我们 spawn 已重命名为 async 作为第二次审核的一部分:

  • 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.

斜体部分已被删除,第三次审核已重新命名:

  • 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.