Socket
Socket
Sign inDemoInstall

retry

Package Overview
Dependencies
0
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.0 to 0.6.0

40

lib/retry_operation.js

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

this._attempts = 1;
this._operationTimeout = null;
this._operationTimeoutCb = null;
this._timeout = null;
}

@@ -11,2 +14,6 @@ module.exports = RetryOperation;

RetryOperation.prototype.retry = function(err) {
if (this._timeout) {
clearTimeout(this._timeout);
}
if (!err) {

@@ -24,10 +31,37 @@ return false;

this._attempts++;
setTimeout(this._fn.bind(this, this._attempts), timeout);
var self = this;
setTimeout(function() {
self._fn(self._attempts);
if (self._operationTimeoutCb) {
self._timeout = setTimeout(function() {
self._operationTimeoutCb(self._attempts);
}, self._operationTimeout);
}
}, timeout);
return true;
};
RetryOperation.prototype.attempt = function(fn) {
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
this._fn = fn;
if (timeoutOps) {
if (timeoutOps.timeout) {
this._operationTimeout = timeoutOps.timeout;
}
if (timeoutOps.cb) {
this._operationTimeoutCb = timeoutOps.cb;
}
}
this._fn(this._attempts);
var self = this;
if (this._operationTimeoutCb) {
this._timeout = setTimeout(function() {
self._operationTimeoutCb();
}, self._operationTimeout);
}
};

@@ -78,2 +112,2 @@

return mainError;
};
};

2

lib/retry.js

@@ -50,2 +50,2 @@ var RetryOperation = require('./retry_operation');

return timeout;
}
};

@@ -5,4 +5,4 @@ {

"description": "Abstraction for exponential and custom retry strategies for failed operations.",
"version": "0.5.0",
"homepage": "https://github.com/felixge/node-retry",
"version": "0.6.0",
"homepage": "https://github.com/tim-kos/node-retry",
"repository": {

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

@@ -123,3 +123,3 @@ # retry

#### retryOperation.attempt(fn)
#### retryOperation.attempt(fn, timeoutOps)

@@ -129,2 +129,6 @@ Defines the function `fn` that is to be retried and executes it for the first

Optionally defines `timeoutOps` which is an object having a property `timeout` in miliseconds and a property `cb` callback function.
Whenever your retry operation takes longer than `timeout` to execute, the timeout callback function `cb` is called.
#### retryOperation.try(fn)

@@ -157,2 +161,6 @@

0.6.0 Introduced optional timeOps parameter for the attempt() function which is an object having a property timeout in miliseconds and a property cb callback function. Whenever your retry operation takes longer than timeout to execute, the timeout callback function cb is called.
0.5.0 Some minor refactorings.
0.4.0 Changed retryOperation.try() to retryOperation.attempt(). Deprecated the aliases start() and try() for it.

@@ -159,0 +167,0 @@

@@ -40,7 +40,15 @@ var common = require('../common');

(function testTry() {
(function testAttempt() {
var operation = retry.operation();
var fn = new Function();
operation.attempt(fn);
var timeoutOpts = {
timeout: 1,
cb: function() {}
};
operation.attempt(fn, timeoutOpts);
assert.strictEqual(fn, operation._fn);
assert.strictEqual(timeoutOpts.timeout, operation._operationTimeout);
assert.strictEqual(timeoutOpts.cb, operation._operationTimeoutCb);
})();

@@ -73,2 +81,2 @@

fn();
})();
})();
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc