runTransaction<T> method
- TransactionHandler<
T> updateFuntion, { - TransactionOptions? transactionOptions,
Executes the given updateFunction and commits the changes applied within the transaction. You can use the transaction object passed to 'updateFunction' to read and modify Firestore documents under lock. You have to perform all reads before before you perform any write. Transactions can be performed as read-only or read-write transactions. By default, transactions are executed in read-write mode. A read-write transaction obtains a pessimistic lock on all documents that are read during the transaction. These locks block other transactions, batched writes, and other non-transactional writes from changing that document. Any writes in a read-write transactions are committed once 'updateFunction' resolves, which also releases all locks. If a read-write transaction fails with contention, the transaction is retried up to five times. The updateFunction is invoked once for each attempt. Read-only transactions do not lock documents. They can be used to read documents at a consistent snapshot in time, which may be up to 60 seconds in the past. Read-only transactions are not retried. Transactions time out after 60 seconds if no documents are read. Transactions that are not committed within than 270 seconds are also aborted. Any remaining locks are released when a transaction times out.
Implementation
Future<T> runTransaction<T>(
TransactionHandler<T> updateFuntion, {
TransactionOptions? transactionOptions,
}) {
if (transactionOptions != null) {}
final transaction = Transaction(this, transactionOptions);
return transaction._runTransaction(updateFuntion);
}