diff options
author | Alexander Early <aearly@fluid.com> | 2016-01-07 15:05:37 -0800 |
---|---|---|
committer | Alexander Early <aearly@fluid.com> | 2016-01-07 15:05:37 -0800 |
commit | f8cea478196657170e829c4205b88ed3ef36cc09 (patch) | |
tree | 6ebc3149af6e83a8fd31fb9ab9b63e676bac4b6b | |
parent | 87fdf85f097d8a55d25eb745e5615344bc453c3a (diff) | |
download | async-f8cea478196657170e829c4205b88ed3ef36cc09.tar.gz |
clarify retry docs. Closes #936
-rw-r--r-- | README.md | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -1445,8 +1445,10 @@ 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 @@ -1454,21 +1456,29 @@ __Arguments__ * `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: |