summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Early <aearly@fluid.com>2015-05-31 19:16:15 -0700
committerAlexander Early <aearly@fluid.com>2015-05-31 19:16:15 -0700
commit4547ee9a1aa7db2cf8494b19448e7f76a843ea3f (patch)
tree8ff5cfb2d36cc51770927821c88c122c54ab79c5
parentc444a508eac3fc183fa4d3fd360221ec12825519 (diff)
downloadasync-4547ee9a1aa7db2cf8494b19448e7f76a843ea3f.tar.gz
updated docs around cargo
-rw-r--r--CHANGELOG.md1
-rw-r--r--README.md1
-rwxr-xr-xtest/test-async.js49
3 files changed, 50 insertions, 1 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 54be579..6b58368 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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)
diff --git a/README.md b/README.md
index 2205fa3..6b29a4f 100644
--- a/README.md
+++ b/README.md
@@ -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__
diff --git a/test/test-async.js b/test/test-async.js
index 7c8fe30..ded054b 100755
--- a/test/test-async.js
+++ b/test/test-async.js
@@ -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');});
+},
};