writeAsync<T> method

Future<T> writeAsync<T>(
  1. T writeCallback(
      ),
    1. [CancellationToken? cancellationToken]
    )

    Executes the provided writeCallback in a temporary write transaction. Both acquiring the write lock and committing the transaction will be done asynchronously.

    Implementation

    Future<T> writeAsync<T>(T Function() writeCallback, [CancellationToken? cancellationToken]) async {
      final transaction = await beginWriteAsync(cancellationToken);
    
      try {
        T result = writeCallback();
        await transaction.commitAsync(cancellationToken);
        return result;
      } catch (e) {
        if (isInTransaction) {
          transaction.rollback();
        }
        rethrow;
      }
    }