【发布时间】:2023-04-10 08:56:02
【问题描述】:
我在我的项目中使用 PromiseKit,我需要对 API 进行批量/多次调用并等待所有响应。任何想法如何做到这一点?我对 PromiseKit 很陌生,在他们的 Github 上没有找到任何关于此的内容(可能没有看到或理解它)
我目前正在尝试但失败的是:
let ids = [1, 2, 3, 4, 5]
firstly {
getURLPathsFor(ids) // maybe I'm doing this wrong - this returns a Promise<[String]>
}.thenMap { url in
ApiManager.shared.request(url, method: .delete)
}.done { _ in
seal.fulfill(())
}.catch { error in
seal.reject(error)
}
func getURLPathsFor(_ ids: [UInt]) -> Promise<[String]> {
let path = "/somePath"
var URLs = [String]()
return Promise { seal in
ids.forEach { uid in
AppConfigManager.shared.getApiUrl(path: path, uid).done { url in
URLs.append(url)
seal.fulfill(URLs)
}.catch { error in
seal.reject(error)
}
}
}
}
任何帮助都会很棒,真的坚持这个。
【问题讨论】:
标签: ios swift promisekit