Skip to content

Commit

Permalink
updated docs around cargo
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander Early committed Jun 1, 2015
1 parent c444a50 commit 4547ee9
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

New Features:

- `cargo` now supports all of the same methods and event callbacks as `queue`.
- Added `ensureAsync` - A wrapper that ensures an async function calls its callback on a later tick. (#769)
- Optimized `map`, `eachOf`, and `waterfall` families of functions
- Reduced file size by 4kb, (minified version by 1kb)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@ methods:
* `saturated` - A callback that is called when the `queue.length()` hits the concurrency and further tasks will be queued.
* `empty` - A callback that is called when the last item from the `queue` is given to a `worker`.
* `drain` - A callback that is called when the last item from the `queue` has returned from the `worker`.
* `idle()`, `pause()`, `resume()`, `kill()` - cargo inherits all of the same methods and event calbacks as [`queue`](#queue)

__Example__

Expand Down
49 changes: 48 additions & 1 deletion test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -3457,7 +3457,54 @@ exports['cargo'] = {
test.equal(drainCounter, 2);
test.done();
}, 1000);
}
},

'events': function(test) {
var calls = [];
var q = async.cargo(function(task, cb) {
// nop
calls.push('process ' + task);
async.setImmediate(cb);
}, 1);
q.concurrency = 3;

q.saturated = function() {
test.ok(q.length() == 3, 'cargo should be saturated now');
calls.push('saturated');
};
q.empty = function() {
test.ok(q.length() === 0, 'cargo should be empty now');
calls.push('empty');
};
q.drain = function() {
test.ok(
q.length() === 0 && q.running() === 0,
'cargo should be empty now and no more workers should be running'
);
calls.push('drain');
test.same(calls, [
'saturated',
'process foo',
'process bar',
'process zoo',
'foo cb',
'process poo',
'bar cb',
'empty',
'process moo',
'zoo cb',
'poo cb',
'moo cb',
'drain'
]);
test.done();
};
q.push('foo', function () {calls.push('foo cb');});
q.push('bar', function () {calls.push('bar cb');});
q.push('zoo', function () {calls.push('zoo cb');});
q.push('poo', function () {calls.push('poo cb');});
q.push('moo', function () {calls.push('moo cb');});
},

};

Expand Down

0 comments on commit 4547ee9

Please sign in to comment.