[英]Swift - Not wait for async to return
我希望能够让class B
中的函数doSomething()
不async
并且不阻塞它的调用者线程。 但是使用以下代码,我得到了这个错误:
无法将“() async -> Void”类型的函数传递给期望同步函数类型的参数
并且 xcode 尝试将class B
中的doSomething()
函数强制为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)
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.