<commit_before>
// Transaction
// -------
var Promise      = require('./promise')
var EventEmitter = require('events').EventEmitter
var inherits     = require('inherits')

var makeKnex     = require('./util/make-knex')
var assign       = require('lodash/object/assign')
var uniqueId     = require('lodash/utility/uniqueId')
var debug        = require('debug')('knex:tx')

// Acts as a facade for a Promise, keeping the internal state
// and managing any child transactions.
function Transaction(client, container, config, outerTx) {
  
  var txid = this.txid = uniqueId('trx')

  this.client    = client
  this.outerTx   = outerTx
  this.trxClient = undefined;
  this._debug    = client.config && client.config.debug

  debug('%s: Starting %s transaction', txid, outerTx ? 'nested' : 'top level')

  this._promise = Promise.using(this.acquireConnection(client, config, txid), (connection) => {
    
    var trxClient = this.trxClient = makeTxClient(this, client, connection)
    var init      = client.transacting ? this.savepoint(connection) : this.begin(connection)
    
    init.then(() => {
      return makeTransactor(this, connection, trxClient)
    })
    .then((transactor) => {

      var result = container(transactor)

      // If we've returned a "thenable" from the transaction container,
      // and it's got the transaction object we're running for this, assume
      // the rollback and commit are chained to this object's success / failure.
      if (result && result.then && typeof result.then === 'function') {
        result.then((val) => {
          transactor.commit(val)
        })
        .catch((err) => {
          transactor.rollback(err)
        })
      }
    
    })
    .catch((e) => this._rejecter(e))

    return new Promise((resolver, rejecter) => {
      this._resolver = resolver
      this._rejecter = rejecter
    })
  })<commit_msg>correct stale transaction promise related implementation comment<commit_after>
// Transaction
// -------
var Promise      = require('./promise')
var EventEmitter = require('events').EventEmitter
var inherits     = require('inherits')

var makeKnex     = require('./util/make-knex')
var assign       = require('lodash/object/assign')
var uniqueId     = require('lodash/utility/uniqueId')
var debug        = require('debug')('knex:tx')

// Acts as a facade for a Promise, keeping the internal state
// and managing any child transactions.
function Transaction(client, container, config, outerTx) {
  
  var txid = this.txid = uniqueId('trx')

  this.client    = client
  this.outerTx   = outerTx
  this.trxClient = undefined;
  this._debug    = client.config && client.config.debug

  debug('%s: Starting %s transaction', txid, outerTx ? 'nested' : 'top level')

  this._promise = Promise.using(this.acquireConnection(client, config, txid), (connection) => {
    
    var trxClient = this.trxClient = makeTxClient(this, client, connection)
    var init      = client.transacting ? this.savepoint(connection) : this.begin(connection)
    
    init.then(() => {
      return makeTransactor(this, connection, trxClient)
    })
    .then((transactor) => {

      var result = container(transactor)

      // If we've returned a "thenable" from the transaction container, assume
      // the rollback and commit are chained to this object's success / failure.
      if (result && result.then && typeof result.then === 'function') {
        result.then((val) => {
          transactor.commit(val)
        })
        .catch((err) => {
          transactor.rollback(err)
        })
      }
    
    })
    .catch((e) => this._rejecter(e))

    return new Promise((resolver, rejecter) => {
      this._resolver = resolver
      this._rejecter = rejecter
    })
  })
{'fraction_non_alphanumeric': 0.13285024154589373, 'fraction_numerical': 0.0, 'mean_word_length': 2.858178053830228, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6156866', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1074, 'n_words': 280}