Permalink
Browse files

Merge branch 'ignore-subsequent-callbacks-on-error'

  • Loading branch information...
2 parents 88e42e5 + f435a52 commit a2c1eb2e151db6b8f76e083f8901e8beb993407b @mbostock mbostock committed Apr 11, 2012
Showing with 23 additions and 5 deletions.
  1. +6 −2 README.md
  2. +1 −1 package.json
  3. +2 −1 queue.js
  4. +1 −1 queue.min.js
  5. +13 −0 test/queue-test.js
View
@@ -1,6 +1,6 @@
# queue.js
- **Queue.js** is yet another asynchronous helper library for JavaScript. Think of it as a minimalist version of [Async.js](https://github.com/caolan/async) that allows fine-tuning over parallelism. Or, think of it as a version of [TameJs](http://tamejs.org/) that does not use code generation.
+**Queue.js** is yet another asynchronous helper library for JavaScript. Think of it as a minimalist version of [Async.js](https://github.com/caolan/async) that allows fine-tuning over parallelism. Or, think of it as a version of [TameJs](http://tamejs.org/) that does not use code generation.
For example, if you wanted to stat two files in parallel:
@@ -29,8 +29,12 @@ Constructs a new queue with the specified *parallelism*. If *parallelism* is not
### queue.defer(method[, arguments…])
-Adds the specified *method* to the queue, with any optional *arguments*.
+Adds the specified *method* to the queue, with any optional *arguments*. The *method* is called with the optional arguments and a final callback argument, which should be called when the task has finished.
### queue.await(callback)
Sets the *callback* to be notified when all deferred tasks have finished.
+
+## Callbacks
+
+The callbacks follow the Node.js convention where the first argument is an optional error object, and the second is used to pass on the result of an operation.
View
@@ -1,6 +1,6 @@
{
"name": "queue",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "A little helper for asynchronous JavaScript.",
"keywords": [
"asynchronous",
View
@@ -2,7 +2,7 @@
if (typeof module === "undefined") self.queue = queue;
else module.exports = queue;
- queue.version = "0.0.1";
+ queue.version = "0.0.2";
function queue(parallelism) {
var queue = {},
@@ -45,6 +45,7 @@
++active;
a.push(function(e, r) {
--active;
+ if (error) return;
if (e) {
if (remaining) {
// clearing remaining cancels subsequent callbacks
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -70,6 +70,19 @@ suite.addBatch({
}
},
+ "queue with multiple tasks where one errors": {
+ topic: function() {
+ queue()
+ .defer(function(callback) { process.nextTick(function() { callback(-1); }); })
+ .defer(function(callback) { process.nextTick(function() { callback(null, 'ok'); }); })
+ .await(this.callback);
+ },
+ "the first error is returned": function(error, results) {
+ assert.equal(error, -1);
+ assert.isNull(results);
+ }
+ },
+
"queue with multiple synchronous tasks that error": {
topic: function() {
queue()

0 comments on commit a2c1eb2

Please sign in to comment.