summaryrefslogtreecommitdiff
path: root/lib/retry.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/retry.js')
-rw-r--r--lib/retry.js22
1 files changed, 9 insertions, 13 deletions
diff --git a/lib/retry.js b/lib/retry.js
index a700516..d8b711b 100644
--- a/lib/retry.js
+++ b/lib/retry.js
@@ -19,10 +19,11 @@ import constant from 'lodash/constant';
* * `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).
- * * `filter` - Synchronous function that is invoked on erroneous result with the
- * the error. If it returns `true` the retry attempts will continue, if the
- * function returns `false` the retry flow is aborting with the current
- * attempt's error and result being returned to the final callback.
+ * * `continueOperation` - An optional synchronous function that is invoked on
+ * erroneous result with the the error. 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
@@ -69,7 +70,7 @@ import constant from 'lodash/constant';
* // try calling apiMethod only when error condition satisfies, all other
* // errors will abort the retry control flow and return to final callback
* async.retry({
- * filter: function(err) {
+ * continueOperation: function(err) {
* return err.message === 'Temporary error'; // only retry on a specific error
* }
* }, apiMethod, function(err, result) {
@@ -103,9 +104,7 @@ export default function retry(opts, task, callback) {
t.interval :
constant(+t.interval || DEFAULT_INTERVAL);
- if(typeof t.filter === 'function') {
- acc.filter = t.filter;
- }
+ acc.continueOperation = t.continueOperation;
} else if (typeof t === 'number' || typeof t === 'string') {
acc.times = +t || DEFAULT_TIMES;
} else {
@@ -129,11 +128,8 @@ export default function retry(opts, task, callback) {
function retryAttempt() {
task(function(err) {
if (err && attempt++ < options.times) {
- var proceed = true;
- if(options.filter) {
- proceed = options.filter(err);
- }
-
+ var proceed = typeof options.continueOperation != 'function' ||
+ options.continueOperation(err);
if(proceed) {
setTimeout(retryAttempt, options.intervalFunc(attempt));
} else {