From 4bf860be31f6ece479df63316db3c2b0cbc97739 Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Tue, 12 Jul 2016 11:11:25 -0400 Subject: Retry passes all arguments to callback --- lib/retry.js | 4 ++-- mocha_test/retry.js | 13 ++++++++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/retry.js b/lib/retry.js index bf0dcf1..8163ad9 100644 --- a/lib/retry.js +++ b/lib/retry.js @@ -109,11 +109,11 @@ export default function retry(opts, task, callback) { var attempt = 1; function retryAttempt() { - task(function(err, result) { + task(function(err) { if (err && attempt++ < options.times) { setTimeout(retryAttempt, options.intervalFunc(attempt)); } else { - callback(err, result); + callback.apply(null, arguments); } }); } diff --git a/mocha_test/retry.js b/mocha_test/retry.js index cc24a29..bed7079 100644 --- a/mocha_test/retry.js +++ b/mocha_test/retry.js @@ -1,6 +1,7 @@ var async = require('../lib'); var expect = require('chai').expect; var assert = require('assert'); +var _ = require('lodash'); describe("retry", function () { @@ -121,7 +122,7 @@ describe("retry", function () { }, 50); }); - it('retry does not precompute the intervals (#1226)',function(done) { + it('retry does not precompute the intervals (#1226)', function(done) { var callTimes = []; function intervalFunc() { callTimes.push(new Date().getTime()); @@ -136,4 +137,14 @@ describe("retry", function () { done(); }); }); + + it('retry passes all resolve arguments to callback', function(done) { + function fn(callback) { + callback(null, 1, 2, 3); // respond with indexed values + } + async.retry(5, fn, _.rest(function(args) { + expect(args).to.be.eql([null, 1, 2, 3]); + done(); + })); + }); }); -- cgit v1.2.1 From 0b5b8b73d9fe5303cce1b11567c92ab21d5d9ed1 Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Tue, 12 Jul 2016 11:16:15 -0400 Subject: Ensure retry can resolve synchronously in fastest case --- mocha_test/retry.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mocha_test/retry.js b/mocha_test/retry.js index bed7079..57b0093 100644 --- a/mocha_test/retry.js +++ b/mocha_test/retry.js @@ -147,4 +147,14 @@ describe("retry", function () { done(); })); }); + + // note this is a synchronous test ensuring retry is synchrnous in the fastest (most straightforward) case + it('retry calls fn immediately and will call callback if successful', function() { + function fn(callback) { + callback(null, {a: 1}); + } + async.retry(5, fn, function(err, result) { + expect(result).to.be.eql({a: 1}); + }); + }) }); -- cgit v1.2.1 From 5aa942de47f5a02a4a200f1477481972b2942e12 Mon Sep 17 00:00:00 2001 From: Graeme Yeates Date: Tue, 12 Jul 2016 11:19:49 -0400 Subject: Update changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3f30505..0053052 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,7 +40,8 @@ Another big performance win has been re-implementing `queue`, `cargo`, and `prio - Added `autoInject`, a relative of `auto` that automatically spreads a task's dependencies as arguments to the task function. (#608, #1055, #1099, #1100) - You can now limit the concurrency of `auto` tasks. (#635, #637) - Added `retryable`, a relative of `retry` that wraps an async function, making it retry when called. (#1058) -- `retry` now supports specifying a function that determines the next time interval, useful for exponential backoff and other retry strategies. (#1161) +- `retry` now supports specifying a function that determines the next time interval, useful for exponential backoff, logging and other retry strategies. (#1161) +- `retry` will now pass all of the arguments the task function was resolved with to the callback (#1231). - Added `q.unsaturated` -- callback called when a `queue`'s number of running workers falls below a threshold. (#868, #1030, #1033, #1034) - Added `q.error` -- a callback called whenever a `queue` task calls its callback with an error. (#1170) - `applyEach` and `applyEachSeries` now pass results to the final callback. (#1088) -- cgit v1.2.1