快速使用 Promisekit for 循环

问题描述

如何在 for 循环中创建一个链并在每个函数执行时返回 Promise ?

嘿伙计们,希望有人可以帮助我使用 swift 和 Promisekit。 我想使用 for 循环从 firebase 下载数据,并在数组已满时返回 Promise 我试过这个代码

    func getAllMatchInformation() -> Promise<[AllMatchInformationModel]> {
        return Promise { seal in
           
        var informationModel : [AllMatchInformationModel]  = []
            for doc in matchDoc {
                firstly{
                    when(fulfilled: self.firestoreManagerChat.getEventWithEventId(eventId: doc.eventId),self.firestoreManagerChat.getUserWithUserId(userId: doc.matchedUserId))
                }.done{ [self] event,user in
                    let info = AllMatchInformationModel(chatId: doc.chatId,user: userModel,event: eventModel)
                    informationModel.append(info)
                    **1) seal.fulfill(informationModel)
                }.catch { error in
                    print(error)
                }
            }
            **2)seal.fulfill(informationModel)
        }
    }
}

当我通过 1 返回 Seal.fulfill 时。)我只从第一次迭代中获取数据,通过 2)我得到一个空数组,因为 for 循环没有执行异步

我在 Stackoverflow 上找到了这个解决方案,但我认为这并不完全相同 Swift & PromiseKit: Resolving ALL promises from a loop

感谢每一个提示

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)