Skip to content

Commit

Permalink
Merge pull request #777 from YouPers/fix775
Browse files Browse the repository at this point in the history
fix(each): each with empty array that has other property never calls final callback.  Closes #775
  • Loading branch information
aearly committed Jun 2, 2015
2 parents ba7c7ba + 63948a8 commit 3b4fd64
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
async.eachOf = function (object, iterator, callback) {
callback = _once(callback || noop);
object = object || [];
var size = object.length || _keys(object).length;
var size = _isArrayLike(object) ? object.length : _keys(object).length;
var completed = 0;
if (!size) {
return callback(null);
Expand Down
16 changes: 16 additions & 0 deletions test/test-async.js
Original file line number Diff line number Diff line change
Expand Up @@ -1375,6 +1375,22 @@ exports['each empty array'] = function(test){
setTimeout(test.done, 25);
};


exports['each empty array, with other property on the array'] = function(test){
test.expect(1);
var myArray = [];
myArray.myProp = "anything";
async.each(myArray, function(x, callback){
test.ok(false, 'iterator should not be called');
callback();
}, function(err){
if (err) throw err;
test.ok(true, 'should call callback');
});
setTimeout(test.done, 25);
};


exports['each error'] = function(test){
test.expect(1);
async.each([1,2,3], function(x, callback){
Expand Down

0 comments on commit 3b4fd64

Please sign in to comment.