Skip to content

Commit

Permalink
always return callback in each
Browse files Browse the repository at this point in the history
  • Loading branch information
Tully committed Jun 10, 2014
1 parent 0a4fa0e commit eb97dd8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
17 changes: 7 additions & 10 deletions releases/latest/amanda.js
Expand Up @@ -68,8 +68,7 @@ var each = function(list, iterator, callback) {
var tryCallback = function() {
if (mayCallback && finished == started) {
// finished all functions, celebrate!
callback();
return;
return callback();
}
}

Expand All @@ -87,19 +86,18 @@ var each = function(list, iterator, callback) {
if (error) {
// if error, fail fast
hasCalled = true;
callback(error);
return;
return callback(error);

}

finished++;
tryCallback();
return;
return tryCallback();

};

// execute right away
started++;
iterator(key, value, cb);
return;
return iterator(key, value, cb);
}


Expand All @@ -124,8 +122,7 @@ var each = function(list, iterator, callback) {

// Done adding items. Allow callback to fire
mayCallback = true
tryCallback();
return;
return tryCallback();
};

if (typeof callback === 'undefined') {
Expand Down
17 changes: 7 additions & 10 deletions src/utils/each.js
Expand Up @@ -51,8 +51,7 @@ var each = function(list, iterator, callback) {
var tryCallback = function() {
if (mayCallback && finished == started) {
// finished all functions, celebrate!
callback();
return;
return callback();
}
}

Expand All @@ -70,19 +69,18 @@ var each = function(list, iterator, callback) {
if (error) {
// if error, fail fast
hasCalled = true;
callback(error);
return;
return callback(error);

}

finished++;
tryCallback();
return;
return tryCallback();

};

// execute right away
started++;
iterator(key, value, cb);
return;
return iterator(key, value, cb);
}


Expand All @@ -107,8 +105,7 @@ var each = function(list, iterator, callback) {

// Done adding items. Allow callback to fire
mayCallback = true
tryCallback();
return;
return tryCallback();
};

if (typeof callback === 'undefined') {
Expand Down

0 comments on commit eb97dd8

Please sign in to comment.