如果 firebase .运行TransactionBlock 完成时出现错误,它会重新 运行 本身吗?

If firebase .runTransactionBlock completes with error, will it re-run itself?

如果此块完成时出错,我应该自己重新运行吗? 我有一个用户日志“客户端在 运行 交易时断开连接”错误,我不太确定如何优雅地处理这个问题。

谢谢大家!

func RunFBTransaction(finished: @escaping () -> Void) {
 ref.child("my_Firebase_Register").runTransactionBlock ({ (currentData: MutableData) -> TransactionResult in
     if var theCount = currentData.value as? Int {
         theCount += 1
         theCount = max(0, theCount)
         currentData.value = theCount
     }
     return TransactionResult.success(withValue: currentData)
 }) { (error, committed, snapshot) in
     if let error = error {
         print("error: \(error.localizedDescription)")
         //should I re-run the RunFBTransaction() again here on error?
         return
     } else {
         finished()
         //if there'a n error and firebase re-run inherently, will this complete out just like normal?
     }
 }

Firebase 实时数据库在 contention/conflicting 写入 to/under 相同路径的情况下自动重试事务。

只有重试次数用完才会调用你的completion handler,报错说明这个问题。如果您想在此时进一步重试事务,则必须在您的应用程序代码中这样做。