【问题标题】:How to avoid pyramid of doom in three database operations?三数据库操作如何避免厄运金字塔?
【发布时间】:2016-10-17 18:34:33
【问题描述】:

从 Web 服务接收数据后,我需要执行三个数据库操作

   self.save(responses, child: child, year: year, completionBlock:
     {(success, error) in
           self.saveModifiedDate(child, year: year, completionBlock: { (result) in
            self.fetchAll(child, year: year!, completionBlock: completionBlock)
            })
      })

【问题讨论】:

    标签: ios swift refactoring swift3


    【解决方案1】:

    您可以尝试使用或实现自己(这并不难)类似 Future 的 API。一个好的框架是FutureKit

    然后代码看起来像

    save(responses, child: child, year: year)
      .onSuccess(saveModifiedDate)
      .onSuccess(fetchAll)
      .onSuccess { //final completion handler }
      .onFailure { //handle error }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-04
      • 2019-02-19
      • 2016-10-14
      • 2021-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多