Repository: caolan/async (js)

Issue:
retry's interval function's argument behavior does not match documentation
<!--
This template is for bug reports. If you are reporting a bug, please continue on. If you are here for another reason (such as a feature request, change, or question) you can disregard this template
-->

**What version of async are you using?**
async-es @ 2.6.1

**Which environment did the issue occur in (Node version/browser version)**
Chrome 68.0.3440.106

**What did you do? Please include a minimal reproducable case illustrating issue.**
```
retry({interval: (x) => { console.log(x); return 0 } }, (err) => err(1))
```
**What did you expect to happen?**
from the docs: 
https://caolan.github.io/async/docs.html#retry

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).
```
// 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
});
```
This implys that the retryCount should, on first call, be called with an argument of 1 as 50 * Math.pow(2, 1) = 100. Then 50 * Math.pow(2, 2) = 200, 3 => 400 ... etc

**What was the actual result?**
The first call to interval's callback function is *2*. The exact argument passed to this callback should be specified in the documents and the example should [be updated to?] match.


Pull request:
fix: send proper retry count to retry's interaval func
Closes #1578

Patch:
diff --git a/lib/retry.js b/lib/retry.js
index 5ef6971..55dce0a 100644
--- a/lib/retry.js
+++ b/lib/retry.js
@@ -122,7 +122,7 @@ export default function retry(opts, task, callback) {
             if (err && attempt++ < options.times &&
                 (typeof options.errorFilter != 'function' ||
                     options.errorFilter(err))) {
-                setTimeout(retryAttempt, options.intervalFunc(attempt));
+                setTimeout(retryAttempt, options.intervalFunc(attempt - 1));
             } else {
                 callback(err, ...args);
             }


Test patch:
diff --git a/test/retry.js b/test/retry.js
index e7bc36a..d6cc06d 100644
--- a/test/retry.js
+++ b/test/retry.js
@@ -79,7 +79,11 @@ describe("retry", () => {
 
     it('retry with custom interval when all attempts fail',(done) => {
         var times = 3;
-        var intervalFunc = function(retryCount) { return retryCount * 100; };
+        var retryCounts = []
+        var intervalFunc = function(retryCount) {
+            retryCounts.push(retryCount)
+            return retryCount * 100;
+        };
         var callCount = 0;
         var error = 'ERROR';
         var erroredResult = 'RESULT';
@@ -94,6 +98,7 @@ describe("retry", () => {
             assert.equal(callCount, 3, "did not retry the correct number of times");
             assert.equal(err, error + times, "Incorrect error was returned");
             assert.equal(result, erroredResult + times, "Incorrect result was returned");
+            assert.deepEqual(retryCounts, [1, 2])
             done();
         });
     });