Permalink
Browse files

Corner case fixed: multiple failures in allOrNone()

  • Loading branch information...
1 parent dedd1a0 commit eca47abb2dd076b00f70833df6b6b7f4bb5e960f @MaxMotovilov MaxMotovilov committed Sep 6, 2012
Showing with 13 additions and 8 deletions.
  1. +1 −1 package.json
  2. +12 −7 promise.js
View
@@ -1,7 +1,7 @@
{
"name": "node-promise",
"description": "Kris Zyp's implementation of promises with added features, maintained as an npm package.",
- "version": "0.5.3",
+ "version": "0.5.4",
"homepage": "https://github.com/MaxMotovilov/node-promise",
"files": [ "package.json", "promise.js", "fs-promise.js" ],
"main": "promise.js",
View
@@ -407,7 +407,9 @@ exports.wait = function(target){
function composeAll(fail_on_error) {
return function(array) {
- var deferred = new Deferred();
+ var deferred = new Deferred(),
+ once = true;
+
if( !(array instanceof Array) )
array = Array.prototype.slice.call(arguments);
else
@@ -418,7 +420,7 @@ function composeAll(fail_on_error) {
else
array.forEach( function( p, i ) {
if( p && p.then )
- exports.when( p, succeed, fail_on_error ? fail : succeed );
+ exports.when( p, succeed, fail_on_error ? failOnce : succeed );
function succeed( v ) {
array[i] = v;
@@ -427,11 +429,14 @@ function composeAll(fail_on_error) {
}
} );
- function fail( err ) {
- array.forEach( function(p) {
- if( p.then && p.cancel ) p.cancel();
- } );
- deferred.reject( err );
+ function failOnce( err ) {
+ if( once ) {
+ array.forEach( function(p) {
+ if( p.then && p.cancel ) p.cancel();
+ } );
+ deferred.reject( err );
+ once = false;
+ }
}
return deferred.promise;

0 comments on commit eca47ab

Please sign in to comment.