class ActiveRecord::ConnectionAdapters::TransactionManager

def within_new_transaction(isolation: nil, joinable: true)

Experimental RBS support (using type sampling data from the type_fusion project).

def within_new_transaction: (isolation: nil, joinable: true) -> nil

This signature was generated using 2 samples from 1 application.

def within_new_transaction(isolation: nil, joinable: true)
  @connection.lock.synchronize do
    transaction = begin_transaction(isolation: isolation, joinable: joinable)
    ret = yield
    completed = true
    ret
  rescue Exception => error
    if transaction
      transaction.state.invalidate! if error.is_a? ActiveRecord::TransactionRollbackError
      rollback_transaction
      after_failure_actions(transaction, error)
    end
    raise
  ensure
    if transaction
      if error
        # @connection still holds an open or invalid transaction, so we must not
        # put it back in the pool for reuse.
        @connection.throw_away! unless transaction.state.rolledback?
      elsif Thread.current.status == "aborting" || (!completed && transaction.written)
        # The transaction is still open but the block returned earlier.
        #
        # The block could return early because of a timeout or because the thread is aborting,
        # so we are rolling back to make sure the timeout didn't caused the transaction to be
        # committed incompletely.
        rollback_transaction
      else
        begin
          commit_transaction
        rescue Exception
          rollback_transaction(transaction) unless transaction.state.completed?
          raise
        end
      end
    end
  end
end