Skip to content

Commit

Permalink
clarify retry docs. Closes #936
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Early committed Jan 7, 2016
1 parent 87fdf85 commit f8cea47
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1445,30 +1445,40 @@ result (if any) of the final attempt.
__Arguments__
* `opts` - Can be either an object with `times` and `interval` or a number. `times` is how many attempts should be made before giving up. `interval` is how long to wait inbetween attempts. Defaults to {times: 5, interval: 0}
* if a number is passed in it sets `times` only (with `interval` defaulting to 0).
* `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`.
* 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
the function's execution, and (2) a `results` object, containing the results of
the previously executed functions (if nested inside another control flow).
* `callback(err, results)` - An optional callback which is called when the
task has succeeded, or after the final failed attempt. It receives the `err` and `result` arguments of the last attempt at completing the `task`.
The [`retry`](#retry) function can be used as a stand-alone control flow by passing a
callback, as shown below:
The [`retry`](#retry) function can be used as a stand-alone control flow by passing a callback, as shown below:
```js
// try calling apiMethod 3 times
async.retry(3, apiMethod, function(err, result) {
// do something with the result
});
```
```js
// try calling apiMethod 3 times, waiting 200 ms between each retry
async.retry({times: 3, interval: 200}, 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) {
// 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:
Expand Down

0 comments on commit f8cea47

Please sign in to comment.