From 94a602d17e4cd183ad9717cf5506f907a02b8d1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Thu, 31 Aug 2017 17:10:17 +0200 Subject: [PATCH] Transaction: Bind timeout to tx instance (#1484) --- lib/transaction.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/transaction.js b/lib/transaction.js index 05fed1a9..39371087 100644 --- a/lib/transaction.js +++ b/lib/transaction.js @@ -76,12 +76,17 @@ TransactionMixin.beginTransaction = function(options, cb) { var connector = this.getConnector(); Transaction.begin(connector, options, function(err, transaction) { if (err) return cb(err); - if (transaction) { + // NOTE(lehni) As part of the process of moving the handling of + // transaction id and timeout from TransactionMixin.beginTransaction() to + // Transaction.begin() in loopback-connector, switch to only setting id + // and timeout if it wasn't taken care of already by Transaction.begin(). + // Eventually, we can remove the following two if-blocks altogether. + if (!transaction.id) { // Set an informational transaction id transaction.id = uuid.v1(); } - if (options.timeout) { - setTimeout(function() { + if (options.timeout && !transaction.timeout) { + transaction.timeout = setTimeout(function() { var context = { transaction: transaction, operation: 'timeout',