summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorAlex Ianus <hire@alexianus.com>2016-05-19 10:19:59 -0400
committerGraeme Yeates <yeatesgraeme@gmail.com>2016-05-21 12:15:04 -0400
commit216a807182c5fa8fb3863279bcde665e30e38304 (patch)
tree88ca95f2655d3dab4a2df85915ea15c83124dcdf /README.md
parent14b164a3797435a56898ef707e94f0cc8eb2464e (diff)
downloadasync-216a807182c5fa8fb3863279bcde665e30e38304.tar.gz
Add docs for retry interval function
Diffstat (limited to 'README.md')
-rw-r--r--README.md17
1 files changed, 16 insertions, 1 deletions
diff --git a/README.md b/README.md
index 0e34285..a428ee5 100644
--- a/README.md
+++ b/README.md
@@ -1570,7 +1570,7 @@ __Arguments__
* `opts` - Can be either an object with `times` and `interval` or a number.
* `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`.
+ * `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).
* If `opts` is a number, the number specifies the number of times to retry, with the default interval of `0`.
* `task(callback, results)` - A function which receives two arguments: (1) a `callback(err, result)`
which must be called when finished, passing `err` (which can be `null`) and the `result` of
@@ -1595,6 +1595,21 @@ async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
});
```
+The interval may also be specified as a function of the retry count:
+
+```js
+// 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
+});
+```
+
```js
// try calling apiMethod the default 5 times no delay between each retry
async.retry(apiMethod, function(err, result) {