From 216a807182c5fa8fb3863279bcde665e30e38304 Mon Sep 17 00:00:00 2001 From: Alex Ianus Date: Thu, 19 May 2016 10:19:59 -0400 Subject: Add docs for retry interval function --- README.md | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'README.md') 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) { -- cgit v1.2.1