aboutsummaryrefslogtreecommitdiff
path: root/node_modules/async/retry.js
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-03 01:33:53 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-03 01:33:53 +0100
commitd1291f67551c58168af43698a359cb5ddfd266b0 (patch)
tree55a13ed29fe1915e3f42f1b1b7038dafa2e975a7 /node_modules/async/retry.js
parentd0a0695fb5d34996850723f7d4b1b59c3df909c2 (diff)
node_modules
Diffstat (limited to 'node_modules/async/retry.js')
-rw-r--r--node_modules/async/retry.js20
1 files changed, 19 insertions, 1 deletions
diff --git a/node_modules/async/retry.js b/node_modules/async/retry.js
index 5ab0d118a..3738be281 100644
--- a/node_modules/async/retry.js
+++ b/node_modules/async/retry.js
@@ -33,6 +33,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* * `interval` - The time to wait between retries, in milliseconds. The
* default is `0`. The interval may also be specified as a function of the
* retry count (see example).
+ * * `errorFilter` - An optional synchronous function that is invoked on
+ * erroneous result. If it returns `true` the retry attempts will continue;
+ * if the function returns `false` the retry flow is aborted with the current
+ * attempt's error and result being returned to the final callback.
+ * Invoked with (err).
* * If `opts` is a number, the number specifies the number of times to retry,
* with the default interval of `0`.
* @param {Function} task - A function which receives two arguments: (1) a
@@ -76,6 +81,16 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* // do something with the result
* });
*
+ * // try calling apiMethod only when error condition satisfies, all other
+ * // errors will abort the retry control flow and return to final callback
+ * async.retry({
+ * errorFilter: function(err) {
+ * return err.message === 'Temporary error'; // only retry on a specific error
+ * }
+ * }, apiMethod, function(err, result) {
+ * // do something with the result
+ * });
+ *
* // It can also be embedded within other control flow functions to retry
* // individual methods that are not as reliable, like this:
* async.auto({
@@ -84,6 +99,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
* }, function(err, results) {
* // do something with the results
* });
+ *
*/
function retry(opts, task, callback) {
var DEFAULT_TIMES = 5;
@@ -99,6 +115,8 @@ function retry(opts, task, callback) {
acc.times = +t.times || DEFAULT_TIMES;
acc.intervalFunc = typeof t.interval === 'function' ? t.interval : (0, _constant2.default)(+t.interval || DEFAULT_INTERVAL);
+
+ acc.errorFilter = t.errorFilter;
} else if (typeof t === 'number' || typeof t === 'string') {
acc.times = +t || DEFAULT_TIMES;
} else {
@@ -121,7 +139,7 @@ function retry(opts, task, callback) {
var attempt = 1;
function retryAttempt() {
task(function (err) {
- if (err && attempt++ < options.times) {
+ if (err && attempt++ < options.times && (typeof options.errorFilter != 'function' || options.errorFilter(err))) {
setTimeout(retryAttempt, options.intervalFunc(attempt));
} else {
callback.apply(null, arguments);