Skip to content

Commit

Permalink
Merge 342df8b into 2056640
Browse files Browse the repository at this point in the history
  • Loading branch information
oliversalzburg committed Aug 20, 2015
2 parents 2056640 + 342df8b commit 8fa80ec
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var retryInstance = new Retry({
* **retryBase** – the base of the delay exponent. Defaults to `1.2`.
* **retryExponent** – the maximum exponent of the delay exponent. If retries are higher than `retryExponent`, `retryExponent` will be used rather than the retry number. Defaults to `33` which means on average max delay of 3m 25s.
* **retryDelay** – a function used to calculate the delay. Replaces the default exponent calculation. If it returns `false` the retries will be aborted.
* **retryLimit** – maximum amount of retries. Defaults to `-1`, which means unlimited retries.
* **log** – a logger function. Defaults to `console.log()`.

## Methods
Expand Down
9 changes: 8 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var Retry = function (options) {
this.options = resolvedOptions;
this.log = resolvedOptions.log;
this.failures = 0;
this.retryLimit = -1;
};

Retry.prototype._try = function () {
Expand Down Expand Up @@ -76,7 +77,13 @@ Retry.prototype._try = function () {
self.retrying = undefined;
self.abort = undefined;

return self._try();

if (self.retryLimit > -1 && self.failures >= self.retryLimit) {
self.end();
return Promise.reject(new Error('Retry limit reached'));
} else {
return self._try();
}
});
};

Expand Down

0 comments on commit 8fa80ec

Please sign in to comment.