Skip to content

Commit

Permalink
Fixed attempt method not handling errors correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
fiznool committed Sep 13, 2016
1 parent d10cb67 commit 86fdd0f
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions lib/backoff.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ var Promise = require('bluebird');
var Errors = require('./errors');

function Backoff(options) {
options = options || {};
this.attempts = 0;
this.minDelay = options.minDelay;
this.maxDelay = options.maxDelay;
this.useRandom = options.useRandom || false;
this.maxAttempts = options.maxAttempts || 5;
this.maxAttempts = options.maxAttempts;

if(options.hasOwnProperty('maxDuration')) {
this.maxDuration = options.maxDuration;
Expand Down Expand Up @@ -97,6 +96,7 @@ BackoffRunner.attempt = function(operation, options, done) {
backoff.attempts++;
operation(function() {
if(arguments.length > 0 && arguments[0]) {
// The operation ended with an error.
if(arguments[0] instanceof BackoffRunner.NonRetryableError) {
// We shouldn't retry.
return done(arguments[0]);
Expand All @@ -106,6 +106,9 @@ BackoffRunner.attempt = function(operation, options, done) {
// Try again after the delay.
return setTimeout(performOperation, delay);
}

// Else, fail.
return done(arguments[0]);
}

// Otherwise, the operation succeeded!
Expand Down

0 comments on commit 86fdd0f

Please sign in to comment.