Skip to content

Commit

Permalink
expose payload again, and allow it to be changed. Closes #744
Browse files Browse the repository at this point in the history
  • Loading branch information
aearly committed Jun 28, 2015
1 parent e37af8d commit 7b3c5c2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,7 @@
var q = {
tasks: [],
concurrency: concurrency,
payload: payload,
saturated: noop,
empty: noop,
drain: noop,
Expand All @@ -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) {
Expand Down
28 changes: 28 additions & 0 deletions test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

};


Expand Down

0 comments on commit 7b3c5c2

Please sign in to comment.