If this block completes with an error, should I re-run it myself? I had a user log "Client was disconnected while running a transaction" error, I'm not quite sure how to handle this gracefully.
Thank you all!
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?
}
}
CodePudding user response:
Firebase Realtime Database automatically retries transactions in the case of contention/conflicting writes to/under the same path.
Only if the number of retries is exhausted will it call your completion handler, with an error indicating this problem. If you want to further retry the transaction at that point, you'll have to do so in your application code.