PromiseKit 如何将 return "when(resolved)" 作为一个 promise?
PromiseKit how to return "when(resolved)" as a promise?
我有一系列函数如下所示:
func getA() -> Promise<Void> {
// code
}
func getB() -> Promise<Void> {
// code
}
func getC() -> Promise<Void> {
// code
}
当所有这些都完成后,我想return一个Promise。这是我尝试过的:
func getStuff() -> Promise<[Result<Void>]> {
return when(resolved: [getA(), getB(), getC()])
}
但我遇到编译错误:'Result' is ambiguous for type lookup in this context
。我怎样才能做到这一点?
您的代码中有几个名为 Result
的东西,您需要告诉 Swift 在这种情况下 Result
指的是 PromiseKit.Result 或使用 Resolution
假设它不在命名空间中并且您不关心相关的 ErrorConsumptionToken。
func getStuff() -> Promise<[Resolution<Void>]> {
return when(resolved: [getA(), getB(), getC()])
}
func getStuff() -> Promise<[PromiseKit.Result<Void>]> {
return when(resolved: [getA(), getB(), getC()])
}
我有一系列函数如下所示:
func getA() -> Promise<Void> {
// code
}
func getB() -> Promise<Void> {
// code
}
func getC() -> Promise<Void> {
// code
}
当所有这些都完成后,我想return一个Promise。这是我尝试过的:
func getStuff() -> Promise<[Result<Void>]> {
return when(resolved: [getA(), getB(), getC()])
}
但我遇到编译错误:'Result' is ambiguous for type lookup in this context
。我怎样才能做到这一点?
您的代码中有几个名为 Result
的东西,您需要告诉 Swift 在这种情况下 Result
指的是 PromiseKit.Result 或使用 Resolution
假设它不在命名空间中并且您不关心相关的 ErrorConsumptionToken。
func getStuff() -> Promise<[Resolution<Void>]> {
return when(resolved: [getA(), getB(), getC()])
}
func getStuff() -> Promise<[PromiseKit.Result<Void>]> {
return when(resolved: [getA(), getB(), getC()])
}