openTransaction method

  1. @override
Future<PostgreSQLConnectionTransactionWrapper> openTransaction(
  1. Transaction transaction
)
override

Implementation

@override
Future<PostgreSQLConnectionTransactionWrapper> openTransaction(
    Transaction transaction) {
  var contextCompleter = Completer<PostgreSQLConnectionTransactionWrapper>();

  var result = executeWithPool(
    (connection) {
      return connection.openTransaction((connTransaction) {
        contextCompleter.complete(connTransaction);

        return transaction.transactionFuture.then(
          (res) => resolveTransactionResult(res, transaction, connection),
          onError: (e, s) {
            cancelTransaction(transaction, connTransaction, e, s);
            throw e;
          },
        );
      });
    },
    validator: (c) => !transaction.isAborted,
    onError: (e, s) => transaction.notifyExecutionError(
      e,
      s,
      errorResolver: resolveError,
      debugInfo: () => transaction.toString(withExecutedOperations: false),
    ),
  );

  transaction.transactionResult = result;

  return contextCompleter.future;
}