diff --git a/CHANGELOG.md b/CHANGELOG.md index 65b27dd05..c665896e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ New Features: - Various internal updates (#786, #801, #802, #803) - Various doc fixes (#790, #794) +Bug Fixes: +- `cargo` now exposes the `payload` size, and `cargo.payload` can be changed on the fly after the `cargo` is created. (#740, #744, #783) # v1.2.1 diff --git a/lib/async.js b/lib/async.js index 4c638ef5c..15475924d 100644 --- a/lib/async.js +++ b/lib/async.js @@ -903,6 +903,7 @@ var q = { tasks: [], concurrency: concurrency, + payload: payload, saturated: noop, empty: noop, drain: noop, @@ -921,8 +922,8 @@ process: function () { if (!q.paused && workers < q.concurrency && q.tasks.length) { while(workers < q.concurrency && q.tasks.length){ - var tasks = payload ? - q.tasks.splice(0, payload) : + var tasks = q.payload ? + q.tasks.splice(0, q.payload) : q.tasks.splice(0, q.tasks.length); var data = _map(tasks, function (task) { diff --git a/test/test-async.js b/test/test-async.js index 52e6a17cd..821d5fab0 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -3797,6 +3797,34 @@ exports['cargo'] = { q.push('moo', function () {calls.push('moo cb');}); }, +'expose payload': function (test) { + test.expect(5); + var called_once = false; + var cargo= async.cargo(function(tasks, cb) { + if (!called_once) { + test.equal(cargo.payload, 1); + test.ok(tasks.length === 1, 'should start with payload = 1'); + } else { + test.equal(cargo.payload, 2); + test.ok(tasks.length === 2, 'next call shold have payload = 2'); + } + called_once = true; + setTimeout(cb, 25); + }, 1); + + cargo.drain = function () { + test.done(); + }; + + test.equals(cargo.payload, 1); + + cargo.push([1, 2, 3]); + + setTimeout(function () { + cargo.payload = 2; + }, 15); +} + };