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

retry

Package Overview
Dependencies
Maintainers
0
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

retry - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

2

example/dns.js

@@ -14,3 +14,3 @@ var dns = require('dns');

operation.try(function() {
operation.try(function(currentAttempt) {
dns.resolve(address, function(err, addresses) {

@@ -17,0 +17,0 @@ if (operation.retry(err)) {

@@ -5,2 +5,3 @@ function RetryOperation(timeouts) {

this._errors = [];
this._attempts = 1;
}

@@ -21,3 +22,4 @@ module.exports = RetryOperation;

setTimeout(this._fn.bind(this), timeout);
this._attempts++;
setTimeout(this._fn.bind(this, this._attempts), timeout);

@@ -29,3 +31,3 @@ return true;

this._fn = fn;
this._fn();
this._fn(this._attempts);
};

@@ -37,2 +39,6 @@

RetryOperation.prototype.attempts = function() {
return this._attempts;
};
RetryOperation.prototype.mainError = function() {

@@ -39,0 +45,0 @@ if (this._errors.length === 0) {

@@ -5,3 +5,3 @@ {

"description": "Abstraction for exponential and custom retry strategies for failed operations.",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/felixge/node-retry",

@@ -8,0 +8,0 @@ "repository": {

@@ -26,3 +26,3 @@ # retry

operation.try(function() {
operation.try(function(currentAttempt) {
dns.resolve(address, function(err, addresses) {

@@ -45,2 +45,3 @@ if (operation.retry(err)) {

backoff. See the API documentation below for all available settings.
currentAttempt is an int representing the number of attempts so far.

@@ -116,3 +117,3 @@ ``` javascript

Defines the function `fn` that is to be retried and executes it for the first
time right away.
time right away. The `fn` function can receive an optional `currentAttempt` callback that represents the number of attempts to execute `fn` so far.

@@ -127,4 +128,8 @@ #### retryOperation.retry(error)

#### retryOperation.attempts()
Returns an int representing the number of attempts it took to call `fn` before it was successful.
## License
retry is licensed under the MIT license.

@@ -51,3 +51,3 @@ var common = require('../common');

var operation = retry.operation([1, 2, 3]);
var retries = 0;
var attempts = 0;

@@ -58,9 +58,11 @@ var finalCallback = fake.callback('finalCallback');

var fn = function() {
operation.try(function() {
operation.try(function(currentAttempt) {
attempts++;
assert.equal(currentAttempt, attempts);
if (operation.retry(error)) {
retries++;
return;
}
assert.strictEqual(retries, 3);
assert.strictEqual(attempts, 4);
assert.strictEqual(operation.attempts(), attempts);
assert.strictEqual(operation.mainError(), error);

@@ -67,0 +69,0 @@ finalCallback();

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