gpt4 book ai didi

swift - 任务组 `async` 与 `spawn`

转载 作者:行者123 更新时间:2023-12-04 11:50:10 25 4
gpt4 key购买 nike

有谁知道,在新的 Swift 中 async/await东东,TaskGroup async有什么区别吗?和 spawn ,或者它们是纯粹的同义词? (如果它们是同义词,我更喜欢 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.

关于swift - 任务组 `async` 与 `spawn`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67980000/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com