runTransaction abstract method

Future<TransactionResult> runTransaction(
  1. TransactionHandler transactionHandler, {
  2. Duration timeout = const Duration(seconds: 5),
})

Atomically modify the data at this location. Unlike a normal set(), which just overwrites the data regardless of its previous value, runTransaction() is used to modify the existing value to a new value, ensuring there are no conflicts with other clients writing to the same location at the same time.

To accomplish this, you pass runTransaction an update function which is used to transform the current value into a new value. If another client writes to the location before your new value is successfully written, your update function will be called again with the new current value, and the write will be retried. This will happen repeatedly until your write succeeds without conflict or you abort the transaction by not returning a value from your update function.

The returned Future will be completed after the transaction has finished.

Implementation

Future<TransactionResult> runTransaction(
    TransactionHandler transactionHandler,
    {Duration timeout = const Duration(seconds: 5)});