Skip to content

Commit f8cea47

Browse files
author
Alexander Early
committed
clarify retry docs. Closes #936
1 parent 87fdf85 commit f8cea47

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

README.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -1445,30 +1445,40 @@ result (if any) of the final attempt.
14451445
14461446
__Arguments__
14471447
1448-
* `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}
1449-
* if a number is passed in it sets `times` only (with `interval` defaulting to 0).
1448+
* `opts` - Can be either an object with `times` and `interval` or a number.
1449+
* `times` - The number of attempts to make before giving up. The default is `5`.
1450+
* `interval` - The time to wait between retries, in milliseconds. The default is `0`.
1451+
* If `opts` is a number, the number specifies the number of times to retry, with the default interval of `0`.
14501452
* `task(callback, results)` - A function which receives two arguments: (1) a `callback(err, result)`
14511453
which must be called when finished, passing `err` (which can be `null`) and the `result` of
14521454
the function's execution, and (2) a `results` object, containing the results of
14531455
the previously executed functions (if nested inside another control flow).
14541456
* `callback(err, results)` - An optional callback which is called when the
14551457
task has succeeded, or after the final failed attempt. It receives the `err` and `result` arguments of the last attempt at completing the `task`.
14561458
1457-
The [`retry`](#retry) function can be used as a stand-alone control flow by passing a
1458-
callback, as shown below:
1459+
The [`retry`](#retry) function can be used as a stand-alone control flow by passing a callback, as shown below:
14591460
14601461
```js
1462+
// try calling apiMethod 3 times
14611463
async.retry(3, apiMethod, function(err, result) {
14621464
// do something with the result
14631465
});
14641466
```
14651467
14661468
```js
1469+
// try calling apiMethod 3 times, waiting 200 ms between each retry
14671470
async.retry({times: 3, interval: 200}, apiMethod, function(err, result) {
14681471
// do something with the result
14691472
});
14701473
```
14711474
1475+
```js
1476+
// try calling apiMethod the default 5 times no delay between each retry
1477+
async.retry(apiMethod, function(err, result) {
1478+
// do something with the result
1479+
});
1480+
```
1481+
14721482
It can also be embedded within other control flow functions to retry individual methods
14731483
that are not as reliable, like this:
14741484

0 commit comments

Comments
 (0)