Sha256: 414bf2f0c9cddfc2309f34030fafce850bf466a8ff610150612974f808fc2e75

Contents?: true

Size: 1.08 KB

Versions: 70

Compression:

Stored size: 1.08 KB

Contents

var RetryOperation = require('./retry_operation');

exports.operation = function(options) {
  var timeouts = exports.timeouts(options);
  return new RetryOperation(timeouts);
};

exports.timeouts = function(options) {
  if (options instanceof Array) {
    return [].concat(options);
  }

  var opts = {
    retries: 10,
    factor: 2,
    minTimeout: 1 * 1000,
    maxTimeout: Infinity,
    randomize: false
  };
  for (var key in options) {
    opts[key] = options[key];
  }

  if (opts.minTimeout > opts.maxTimeout) {
    throw new Error('minTimeout is greater than maxTimeout');
  }

  var timeouts = [];
  for (var i = 0; i < opts.retries; i++) {
    timeouts.push(this._createTimeout(i, opts));
  }

  // sort the array numerically ascending
  timeouts.sort(function(a,b) {
    return a - b;
  });

  return timeouts;
};

exports._createTimeout = function(attempt, opts) {
  var random = (opts.randomize)
    ? (Math.random() + 1)
    : 1;

  var timeout = Math.round(random * opts.minTimeout * Math.pow(opts.factor, attempt));
  timeout = Math.min(timeout, opts.maxTimeout);

  return timeout;
};

Version data entries

70 entries across 70 versions & 3 rubygems

Version Path
trusty-festivity-extension-2.5.3 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.5.2 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.5.1 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.5.0 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.4.6 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.4.5 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.4.4 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.4.3 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.4.2 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.4.1 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.4.0 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.30 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.29 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.28 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.27 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.26 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.25 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.24 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.23 node_modules/bower/node_modules/retry/lib/retry.js
trusty-festivity-extension-2.3.22 node_modules/bower/node_modules/retry/lib/retry.js