runTransaction method

Future runTransaction(
  1. dynamic updateFunction(
    1. Transaction
    )
)

Executes the given updateFunction and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, Cloud Firestore retries the updateFunction. If it fails to commit after 5 attempts, the transaction fails.

Returns non-null Future if the transaction completed successfully or was explicitly aborted (the updateFunction returned a failed Future), the Future returned by the updateFunction is returned here. Else, if the transaction failed, a rejected Future with the corresponding failure error will be returned.

Implementation

Future runTransaction(Function(Transaction) updateFunction) async {
  final updateFunctionWrap = allowInterop((transaction) =>
      handleFutureWithMapper(
          updateFunction(Transaction.getInstance(transaction)), jsify));

  final value =
      await handleThenable(jsObject.runTransaction(updateFunctionWrap));
  return dartify(value);
}