Skip to content

Commit

Permalink
Merge pull request #420 from chok/include-callbacks
Browse files Browse the repository at this point in the history
Fix empty callbacks with many includes
  • Loading branch information
1602 committed Aug 18, 2014
2 parents ac53d0a + 1a049f9 commit 93d9bca
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/include.js
Expand Up @@ -43,20 +43,24 @@ AbstractClass.include = function (objects, include, cb) {
var objsByKeys = {};

var nbCallbacks = 0;
var totalCallbacks = 0;

for (var i = 0; i < include.length; i++) {
var callback = processIncludeItem(this, objects, include[i], keyVals, objsByKeys);
if (callback !== null) {
totalCallbacks++;
if (callback instanceof Error) {
cb(callback);
} else {
includeItemCallback(callback);
}
} else {
cb(null, objects);
}
}

if (totalCallbacks == 0) {
cb(null, objects);
}

function includeItemCallback(itemCb) {
nbCallbacks++;
itemCb(function () {
Expand Down

0 comments on commit 93d9bca

Please sign in to comment.