Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

backoff

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

backoff - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1

16

lib/strategy/exponential.js

@@ -5,2 +5,3 @@ // Copyright (c) 2012 Mathieu Turcotte

var util = require('util');
var precond = require('precond');

@@ -14,8 +15,21 @@ var BackoffStrategy = require('./strategy');

this.nextBackoffDelay_ = this.getInitialDelay();
this.factor_ = ExponentialBackoffStrategy.DEFAULT_FACTOR;
if (options && options.factor !== undefined) {
precond.checkArgument(options.factor > 1,
'Exponential factor should be greater than 1 but got %s.',
options.factor);
this.factor_ = options.factor;
}
}
util.inherits(ExponentialBackoffStrategy, BackoffStrategy);
// Default multiplication factor used to compute the next backoff delay from
// the current one. The value can be overridden by passing a custom factor as
// part of the options.
ExponentialBackoffStrategy.DEFAULT_FACTOR = 2;
ExponentialBackoffStrategy.prototype.next_ = function() {
this.backoffDelay_ = Math.min(this.nextBackoffDelay_, this.getMaxDelay());
this.nextBackoffDelay_ = this.backoffDelay_ * 2;
this.nextBackoffDelay_ = this.backoffDelay_ * this.factor_;
return this.backoffDelay_;

@@ -22,0 +36,0 @@ };

7

package.json
{
"name": "backoff",
"description": "Fibonacci and exponential backoffs.",
"version": "2.4.0",
"version": "2.4.1",
"license": "MIT",

@@ -27,6 +27,7 @@ "author": "Mathieu Turcotte <turcotte.mat@gmail.com>",

},
"file": [
"files": [
"index.js",
"lib"
"lib",
"tests"
]
}

@@ -113,4 +113,12 @@ # Backoff for Node.js

See bellow for options description.
The options are the following.
- randomisationFactor: defaults to 0, must be between 0 and 1
- initialDelay: defaults to 100 ms
- maxDelay: defaults to 10000 ms
With these values, the backoff delay will increase from 100 ms to 10000 ms. The
randomisation factor controls the range of randomness and must be between 0
and 1. By default, no randomisation is applied on the backoff delay.
### backoff.exponential([options])

@@ -125,2 +133,3 @@

- maxDelay: defaults to 10000 ms
- factor: defaults to 2, must be greater than 1

@@ -234,2 +243,3 @@ With these values, the backoff delay will increase from 100 ms to 10000 ms. The

- maxDelay: defaults to 10000 ms
- factor: defaults to 2, must be greater than 1

@@ -304,5 +314,5 @@ ### Class FibonacciStrategy

Returns an array containing the results returned by the last wrapped function
call. For example, to get the error code returned by the last call, one would
do the following.
Returns an array containing the arguments passed to the completion callback of
the wrapped function. For example, to get the error code returned by the last
call, one would do the following.

@@ -309,0 +319,0 @@ ``` js

@@ -11,19 +11,15 @@ /*

exports["ExponentialBackoffStrategy"] = {
setUp: function(callback) {
this.strategy = new ExponentialBackoffStrategy({
"backoff delays should follow an exponential sequence": function(test) {
var strategy = new ExponentialBackoffStrategy({
initialDelay: 10,
maxDelay: 1000
});
callback();
},
"backoff delays should follow an exponential sequence": function(test) {
// Exponential sequence: x[i] = x[i-1] * 2.
var expectedDelays = [10, 20, 40, 80, 160, 320, 640, 1000, 1000];
var actualDelays = [];
var actualDelays = expectedDelays.map(function () {
return strategy.next();
});
for (var i = 0; i < expectedDelays.length; i++) {
actualDelays.push(this.strategy.next());
}
test.deepEqual(expectedDelays, actualDelays,

@@ -34,2 +30,20 @@ 'Generated delays should follow an exponential sequence.');

"backoff delay factor should be configurable": function (test) {
var strategy = new ExponentialBackoffStrategy({
initialDelay: 10,
maxDelay: 270,
factor: 3
});
// Exponential sequence: x[i] = x[i-1] * 3.
var expectedDelays = [10, 30, 90, 270, 270];
var actualDelays = expectedDelays.map(function () {
return strategy.next();
});
test.deepEqual(expectedDelays, actualDelays,
'Generated delays should follow a configurable exponential sequence.');
test.done();
},
"backoff delays should restart from the initial delay after reset": function(test) {

@@ -36,0 +50,0 @@ var strategy = new ExponentialBackoffStrategy({

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc