tim-kos / node-retry

Abstraction for exponential and custom retry strategies for failed operations.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

increase attempts at the time when retry function starts to execute

life0fun opened this issue · comments

Quick fix to ensure attempts got increased at the time when retry function got invoked.
Otherwise, the _attempts is not accurate as the retry actually got executed after timeout.
Too lazy for a pull request. Just paste the patch here.

diff --git a/lib/retry_operation.js b/lib/retry_operation.js
index f24d2d5..07add06 100644
--- a/lib/retry_operation.js
+++ b/lib/retry_operation.js
@@ -25,10 +25,9 @@ RetryOperation.prototype.retry = function(err) {
     return false;
   }

-  this._attempts++;
-
   var self = this;
   setTimeout(function() {
+    self._attempts++;
     self._fn(self._attempts);

     if (self._operationTimeoutCb) {
@@ -106,4 +105,4 @@ RetryOperation.prototype.mainError = function() {
   }

   return mainError;
-};
\ No newline at end of file
+};