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 1.2.0 to 1.2.1

tests/api.js

1

examples/fibonacci.js

@@ -23,2 +23,1 @@ #!/usr/bin/env node

testBackoff.backoff();

@@ -56,2 +56,1 @@ #!/usr/bin/env node

call.failAfter(2);

@@ -54,2 +54,1 @@ /*

};

@@ -83,2 +83,1 @@ /*

module.exports = Backoff;

@@ -59,10 +59,11 @@ /*

* @return A backoff instance.
* @private
*/
FunctionCall.backoffFactory = function(strategy) {
FunctionCall.backoffFactory_ = function(strategy) {
return new Backoff(strategy || new FibonacciBackoffStrategy());
};
/**
* Default number of backoffs.
* @private
*/

@@ -126,3 +127,3 @@ FunctionCall.prototype.failAfter_ = 5;

backoffFactory = backoffFactory || FunctionCall.backoffFactory;
backoffFactory = backoffFactory || FunctionCall.backoffFactory_;

@@ -181,2 +182,8 @@ this.backoff_ = backoffFactory(this.strategy_);

/**
* Handles backoff event.
* @param number Backoff number.
* @param delay Backoff delay.
* @private
*/
FunctionCall.prototype.handleBackoff_ = function(number, delay) {

@@ -183,0 +190,0 @@ this.emit('backoff', number, delay);

@@ -35,2 +35,1 @@ /*

module.exports = ExponentialBackoffStrategy;

@@ -36,2 +36,1 @@ /*

module.exports = FibonacciBackoffStrategy;

@@ -99,2 +99,1 @@ /*

module.exports = BackoffStrategy;
{
"name": "backoff",
"description": "Fibonacci and exponential backoffs.",
"version": "1.2.0",
"version": "1.2.1",
"author": "Mathieu Turcotte <turcotte.mat@gmail.com>",
"keywords": ["backoff", "fibonacci", "exponential"],
"keywords": ["backoff", "retry", "fibonacci", "exponential"],
"repository": {

@@ -8,0 +8,0 @@ "type": "git",

@@ -85,3 +85,3 @@ # Backoff for Node.js [![Build Status](https://secure.travis-ci.org/MathieuTurcotte/node-backoff.png?branch=master)](http://travis-ci.org/MathieuTurcotte/node-backoff)

It's also possible to avoid some boilerplate code when invoking an asynchronous
function in a backoff loop by using `backoff.call(fn, args)`.
function in a backoff loop by using `backoff.call(fn, [args, ...], callback)`.

@@ -135,5 +135,4 @@ Typical usage looks like the following.

automatically retried on error. The wrapped function will get retried until it
succeds or reach the maximum number of backoffs. In both cases, the callback
function will be invoked with the last results returned by the wrapped
function.
succeds or reaches the maximum number of backoffs. In both cases, the callback
function will be invoked with the last result returned by the wrapped function.

@@ -307,3 +306,3 @@ This function returns a `FunctionCall` instance that is going to be invoked on

Emitted each time the wrapped function invoke its callback.
Emitted each time the wrapped function invokes its callback.

@@ -310,0 +309,0 @@ #### Event: 'backoff'

@@ -16,2 +16,3 @@ /*

this.clock = sinon.useFakeTimers();
this.spy = new sinon.spy();
callback();

@@ -27,9 +28,7 @@ },

this.backoffStrategy.next.returns(10);
this.backoff.on('backoff', this.spy);
var spy = new sinon.spy();
this.backoff.on('backoff', spy);
this.backoff.backoff();
test.ok(spy.calledOnce,
test.ok(this.spy.calledOnce,
'Backoff event should be emitted when backoff starts.');

@@ -41,10 +40,8 @@ test.done();

this.backoffStrategy.next.returns(10);
this.backoff.on('ready', this.spy);
var spy = new sinon.spy();
this.backoff.on('ready', spy);
this.backoff.backoff();
this.clock.tick(10);
test.ok(spy.calledOnce,
test.ok(this.spy.calledOnce,
'Ready event should be emitted when backoff ends.');

@@ -56,9 +53,7 @@ test.done();

this.backoffStrategy.next.returns(989);
this.backoff.on('backoff', this.spy);
var spy = new sinon.spy();
this.backoff.on('backoff', spy);
this.backoff.backoff();
test.equal(spy.getCall(0).args[1], 989, 'Backoff event should ' +
test.equal(this.spy.getCall(0).args[1], 989, 'Backoff event should ' +
'carry the backoff delay as its second argument.');

@@ -70,10 +65,8 @@ test.done();

this.backoffStrategy.next.returns(989);
this.backoff.on('ready', this.spy);
var spy = new sinon.spy();
this.backoff.on('ready', spy);
this.backoff.backoff();
this.clock.tick(989);
test.equal(spy.getCall(0).args[1], 989, 'Ready event should ' +
test.equal(this.spy.getCall(0).args[1], 989, 'Ready event should ' +
'carry the backoff delay as its second argument.');

@@ -85,4 +78,3 @@ test.done();

this.backoffStrategy.next.returns(10);
var spy = new sinon.spy();
this.backoff.on('fail', spy);
this.backoff.on('fail', this.spy);

@@ -98,5 +90,5 @@ this.backoff.failAfter(2);

// Failure should occur on the third call, and not before.
test.ok(!spy.calledOnce, 'Fail event shouldn\'t have been emitted.');
test.ok(!this.spy.calledOnce, 'Fail event shouldn\'t have been emitted.');
this.backoff.backoff();
test.ok(spy.calledOnce, 'Fail event should have been emitted.');
test.ok(this.spy.calledOnce, 'Fail event should have been emitted.');

@@ -129,6 +121,4 @@ test.done();

this.backoffStrategy.next.returns(10);
this.backoff.on('ready', this.spy);
var spy = new sinon.spy();
this.backoff.on('ready', spy);
this.backoff.backoff();

@@ -139,3 +129,3 @@

test.equals(spy.callCount, 0, 'Reset should have aborted the backoff.');
test.equals(this.spy.callCount, 0, 'Reset should have aborted the backoff.');
test.done();

@@ -167,7 +157,6 @@ },

this.backoffStrategy.next.returns(10);
var expectedNumbers = [0, 1, 2, 3, 4],
actualNumbers = [];
this.backoff.on('backoff', this.spy);
var spy = new sinon.spy();
this.backoff.on('backoff', spy);
var expectedNumbers = [0, 1, 2, 3, 4];
var actualNumbers = [];

@@ -177,3 +166,3 @@ for (var i = 0; i < expectedNumbers.length; i++) {

this.clock.tick(10);
actualNumbers.push(spy.getCall(i).args[0]);
actualNumbers.push(this.spy.getCall(i).args[0]);
}

@@ -180,0 +169,0 @@

Sorry, the diff of this file is not supported yet

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