summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <alexander.early@gmail.com>2015-06-27 23:10:48 -0700
committerAlexander Early <alexander.early@gmail.com>2015-06-27 23:10:48 -0700
commit7b3c5c21b156ca787a11ea7e5e54fc784277b1ae (patch)
tree079cb14c4f3c7d4882943038b7c4dfd0df695d6c
parente37af8d1214a5e7be21d6a86615d094ef38a8eea (diff)
downloadasync-7b3c5c21b156ca787a11ea7e5e54fc784277b1ae.tar.gz
expose payload again, and allow it to be changed. Closes #744
-rw-r--r--CHANGELOG.md2
-rw-r--r--lib/async.js5
-rwxr-xr-xtest/test-async.js28
3 files changed, 33 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 65b27dd..c665896 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 4c638ef..1547592 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 52e6a17..821d5fa 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);
+}
+
};