diff options
author | Alex Ianus <hire@alexianus.com> | 2016-05-19 10:19:59 -0400 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-05-21 12:15:04 -0400 |
commit | 216a807182c5fa8fb3863279bcde665e30e38304 (patch) | |
tree | 88ca95f2655d3dab4a2df85915ea15c83124dcdf /lib | |
parent | 14b164a3797435a56898ef707e94f0cc8eb2464e (diff) | |
download | async-216a807182c5fa8fb3863279bcde665e30e38304.tar.gz |
Add docs for retry interval function
Diffstat (limited to 'lib')
-rw-r--r-- | lib/retry.js | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/lib/retry.js b/lib/retry.js index 99040e8..633b418 100644 --- a/lib/retry.js +++ b/lib/retry.js @@ -19,7 +19,8 @@ import constant from 'lodash/constant'; * * `times` - The number of attempts to make before giving up. The default * is `5`. * * `interval` - The time to wait between retries, in milliseconds. The - * default is `0`. + * default is `0`. The interval may also be specified as a function of the + * retry count (see example). * * 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 @@ -47,7 +48,18 @@ import constant from 'lodash/constant'; * // do something with the result * }); * - * // try calling apiMethod the default 5 times no delay between each retry + * // try calling apiMethod 10 times with exponential backoff + * // (i.e. intervals of 100, 200, 400, 800, 1600, ... milliseconds) + * async.retry({ + * times: 10, + * interval: function(retryCount) { + * return 50 * Math.pow(2, retryCount); + * } + * }, apiMethod, function(err, result) { + * // do something with the result + * }); + * + * // try calling apiMethod the default 5 times no delay between each retry * async.retry(apiMethod, function(err, result) { * // do something with the result * }); |