diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/async.js | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/lib/async.js b/lib/async.js index 1f1e0ef..a7743f5 100644 --- a/lib/async.js +++ b/lib/async.js @@ -77,12 +77,6 @@ ); } - function _each(coll, iterator) { - return _isArrayLike(coll) ? - _arrayEach(coll, iterator) : - _forEachOf(coll, iterator); - } - function _arrayEach(arr, iterator) { var index = -1, length = arr.length; @@ -230,23 +224,26 @@ async.eachOf = function (object, iterator, callback) { callback = _once(callback || noop); object = object || []; - var size = _isArrayLike(object) ? object.length : _keys(object).length; - var completed = 0; - if (!size) { - return callback(null); - } - _each(object, function (value, key) { + + var iter = _keyIterator(object); + var key, completed = 0; + + while ((key = iter()) != null) { + completed += 1; iterator(object[key], key, only_once(done)); - }); + } + + if (completed === 0) callback(null); + function done(err) { + completed--; if (err) { callback(err); } - else { - completed += 1; - if (completed >= size) { - callback(null); - } + // Check key is null in case iterator isn't exhausted + // and done resolved synchronously. + else if (key === null && completed <= 0) { + callback(null); } } }; |