【发布时间】:2021-12-01 00:34:47
【问题描述】:
我希望能够让来自class B 的函数doSomething() 不是async 并且不阻塞它的调用者线程。但是使用以下代码我得到了这个错误:
无法将“() async -> Void”类型的函数传递给期望同步函数类型的参数
并且 xcode 尝试将 doSomething() 函数从 class B 强制为 async
class A {
func doSomething() async throws {
//perform
}
}
class B {
let a = A()
func doSomething() {
DispatchQueue.global().async {
do {
await try a.doSomething()
} catch {
print(error)
}
}
}
}
【问题讨论】:
标签: ios swift async-await structured-concurrency