Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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

  • Loading branch information...
commit a2c1eb2e151db6b8f76e083f8901e8beb993407b 2 parents 88e42e5 + f435a52
@mbostock authored
View
8 README.md
@@ -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
2  package.json
@@ -1,6 +1,6 @@
{
"name": "queue",
- "version": "0.0.1",
+ "version": "0.0.2",
"description": "A little helper for asynchronous JavaScript.",
"keywords": [
"asynchronous",
View
3  queue.js
@@ -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
2  queue.min.js
@@ -1 +1 @@
-(function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d,a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.1"})();
+(function(){function a(a){function l(){if(g&&d<a){var b=g,c=b[0],f=Array.prototype.slice.call(b,1),m=b.index;g===h?g=h=null:g=g.next,++d,f.push(function(a,b){--d;if(i)return;a?e&&k(i=a,e=j=g=h=null):(j[m]=b,--e?l():k(null,j))}),c.apply(null,f)}}var c={},d=0,e=0,f=-1,g,h,i=null,j=[],k=b;return arguments.length<1&&(a=Infinity),c.defer=function(){if(!i){var a=arguments;a.index=++f,h?(h.next=a,h=h.next):g=h=a,++e,l()}return c},c.await=function(a){return k=a,e||k(i,j),c},c}function b(){}typeof module=="undefined"?self.queue=a:module.exports=a,a.version="0.0.2"})();
View
13 test/queue-test.js
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.