start method

Future<T> start({
  1. TransactionHeaders? headers,
  2. int maxWait = 2000,
  3. int timeout = 5000,
  4. TransactionIsolationLevel? isolationLevel,
})

Start a new transaction.

Implementation

Future<T> start({
  TransactionHeaders? headers,
  int maxWait = 2000,
  int timeout = 5000,
  TransactionIsolationLevel? isolationLevel,
}) async {
  if (this.transaction?.id != null) {
    throw Exception('Cannot nest start transactions.');
  }

  headers ??= TransactionHeaders();
  headers.traceparent ??= generateTraceparent();

  final transaction = await _engine.startTransaction(
    headers: headers,
    maxWait: maxWait,
    timeout: timeout,
    isolationLevel: isolationLevel,
  );
  final client = TransactionClient._(
    factory: _factory,
    engine: _engine,
    headers: headers,
    transaction: transaction,
  );

  return _factory(client);
}