【发布时间】:2022-01-03 08:38:52
【问题描述】:
在 swift 的新结构化并发模型中是否有在没有虚拟 bool 返回的情况下执行以下操作?
func do() async -> Bool {
something()
return true
}
async let foo = do()
//do other stuff
stuff()
//now I need to know that "do" has finished
await foo
我知道我可以执行以下操作,但不会同时运行:
func do() async {
something()
}
await do()
stuff()
//cannot run "stuff" and "do" concurrently
我觉得我在这里遗漏了一个基本概念,因为顶部的代码块可以满足我的需要,但由于返回 Bool,感觉就像是 hack。
【问题讨论】:
标签: swift async-await concurrency